VC FTP服务端与客户端

1 FTP服务端 http://www.codeproject.com/KB/IP/ftpserver.aspx

 

   没有根目录的设置,暂时没有找到,后面如果需要自己就加上了

CFTPServer

This class is in fact the FTP server, and controls all other classes needed for the server to work. Although CFTPServer is part of a dialog based application, it does not rely on a User Interface and can easily be implemented in a service or console application as well.

  • BOOL Start()

    Activates the FTP server. It opens a listening socket (port 21) to accept connections.

  • void Stop()

    Deactivates the server and disconnects all connected clients by terminating the running threads.

  • BOOL IsActive()

    Is FTP server active?

  • void SetMaxUsers(int nValue)

    Set maximum number of users.

  • void SetPort(int nValue)

    Set listening port for new connections.

  • void SetTimeout(int nValue)

    Set connection timeout (in ms). When a client does not send any commands for nValue ms, the server will close the connection.

  • void SetWelcomeMessage(LPCTSTR lpszText)

    Set the text that will be displayed when the client logs on.

  • void Initialize(CFTPEventSink *pEventSink)

    Set the event sink. The event sink will be the window (or any class) that receives the events generated by the FTP server. See CFTPEventSink description for more info.

Sample Image

 

 

2 FTP客户端  http://www.codeproject.com/KB/IP/ftpclientclass.aspx

  看了下,没有目录的相关操作,有点遗憾

 

nsFTP::CFTPClient ftpClient;
nsFTP::CLogonInfo logonInfo("localhost", 21, "anonymous", "[email protected]");

// connect to server
ftpClient.Login(logonInfo);

// get directory listing
nsFTP::TSpFTPFileStatusVector list;
ftpClient.List("/", list);

// iterate listing
for( nsFTP::TSpFTPFileStatusVector::iterator it=list.begin();
it!=list.end(); ++it )
TRACE("/n%s", (*it)->Name().c_str());

// do file operations
ftpClient.DownloadFile("/pub/test.txt", "c://temp//test.txt");

ftpClient.UploadFile("c://temp//test.txt", "/upload/test.txt");

ftpClient.RenameFile("/upload/test.txt", "/upload/NewName.txt");

ftpClient.Delete("/upload/NewName.txt");

// disconnect
ftpClient.Logout();

 

还是个好东西

你可能感兴趣的:(ftp)