且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用文件名将文件从一个文件夹移动到另一个文件夹?

更新时间:2022-12-03 21:36:32

好的,显然你喜欢重新发明***,你可以使用FTP来实现这个目标....我要做的是发送一个固定大小的数据包开始,包含服务器端的信息 - 你可能有类似的事情



文件名 - 512字节

文件大小 - 4个字节长int?

CRC - x个字节



服务器从客户端收到此数据包然后接收文件大小字节的数据流,将其存储在临时文件中,并检查CRC - 如果一切正常,则将临时文件复制到文件名所指示的名称 - 显然是512字节fr文件名,长4个字节对于CRC,int,x字节必须是适合您系统的值



还有其他协议你可以看一下btw,为了灵感/帮助,'kermit'涌到mind
ok, obviously you love re-inventing the wheel, you could use FTP for this .... what I would do is send a fixed size packet to start with, containing information for the server side - you may have things like

Filename - 512 bytes
File Size - 4 bytes long int ?
CRC - x bytes

the server receives this 'packet' from the client, then receives a data stream for File Size bytes storing it in a temporary file, and checks the CRC - if all is ok, it copies the temp file to the name indicated by the Filename - obviously the 512 bytes fr Filename, 4 bytes long int, x bytes for the CRC must be values appropriate for your system

there are other protocols you could look at btw, for inspiration/help , 'kermit' springs to mind


venkat28写道:
venkat28 wrote:



@sergey。上面的代码是否可用于从客户端读取文件名及其内容,并将其发送到服务器中的所需位置。如果你发现任何错误,请指导我。


@sergey. Will the code above code for work for reading a filename and its contents from client and send it to server, in the desired location in the server. If u find any errors, kindly guide me.

让我们从第一个开始:

Let's start with the first one:

char *str="/home/sosdt009/Documents";



您正在对名为receive_text的函数中的某些路径进行硬编码。如果在任何地方使用此路径,则表示该函数不接收文件;它将一些文件放到一些硬编码的位置。



整个想法都错了。您需要定义一些基于TCP的应用层协议。 这样的协议,根据定义,应该定义两个部分的行为,而不仅仅是一个:服务器端和客户端。



请参阅:

应用层 - ***,免费的百科全书 [ ^ ],

互联网协议套件 - ***,免费的百科全书 [ ^ ],

通讯协议 - ***,免费的百科全书 [ ^ ],

传输控制协议 - ***,fr ee百科全书 [ ^ ]。



-SA


You are hard-coding some path inside the function called "receive_text". If this path is used anywhere, it means the function does not receive file; it puts some file to some hard-coded location.

The whole idea is wrong. You need to define some application-layer protocol based on TCP. Such protocol, by definitions, should define behavior of two parts, not just one: server-side and client-side.

Please see:
Application layer - Wikipedia, the free encyclopedia[^],
Internet protocol suite - Wikipedia, the free encyclopedia[^],
Communications protocol - Wikipedia, the free encyclopedia[^],
Transmission Control Protocol - Wikipedia, the free encyclopedia[^].

—SA