FTP发送命令下载问题

时间:2022-05-11 23:47:33
登录上去之后,数据连接也连接上了,依次发送
SYST    215 UNIX Type: L8
CWD   250 Directory successfully changed.
TYPE   200 Switching to Binary mode.
REST   350 Restart position accepted (0)
RETR  xxx.txt
就出现 550 Failed to open file.
 这些命令有什么顺序要求吗?还是应该怎么组合?
 xxx.txt确实是cwd 设置的工作目录下面的。百思不得其解啊。我都被烦死了。求高手指点。
 

2 个解决方案

#1


Linux 的不懂, Windows的 有  FtpGetFile


Creating a Synchronous Example
Suppose that you want to connect to an FTP server called ftp://ftp.infosite.com and copy all of the .ZIP files from its /BIN subdirectory to your local hard drive and store them in your C:\ZIPFILES subdirectory. The sample code might look like this:

HINTERNET hInternetSession;          // handle to internet connection
HINTERNET hFTPSession;               // handle to FTP session
HINTERNET hFileConnection;           // handle to file enumeration
WIN32_FIND_DATA sWFD;                // structure to hold FIND data
BOOL bResult = TRUE;                 // Boolean for return code
CString InputSpec;                   // variable to hold input spec
Cstring OutputSpec;                  // variable to hold output spec

hInternetSession = InternetOpen(
                  "Microsoft Internet Explorer",     // agent
                  INTERNET_OPEN_TYPE_PROXY,          // access
                  "ftp-gw",                          // proxy server
                  NULL,                              // defaults
                  0);                                // synchronous

// Make connection to ftp server.
hFTPSession = ::InternetConnect(
         hInternetSession,                // Handle from a previous
                                          // call to InternetOpen.
         "ftp://ftp.infosite.com",        // Server we want to connect to
         INTERNET_INVALID_PORT_NUMBER,    // Use appropriate port.
         NULL,                            // Use anonymous for username.
         NULL,                            // Use e-mail name for password
         INTERNET_SERVICE_FTP,            // Flag to use FTP services
         0,                               // Flags (see SDK docs)
         0);                              // Synchronous mode

// Find first .ZIP file.
hFileConnection = ::FtpFindFirstFile(
                    hFTPSession,
                    "*.ZIP",
                    &sWFD,
                    0,
                    0);
if (hFileConnection != (HINTERNET)NULL)
   {
   ::FtpSetCurrentDirectory(hFTPSession, "/BIN");

   while (bResult)
      {
      // Create file specs.
      InputSpec = "ftp://ftp.infosite.com/BIN/";
      InputSpec = InputSpec + sWFD.cFileName;
      OutputSpec = "c:\zipfiles\";
      OutputSpec = OutputSpec + sWFD.cFileName;

      // Transfer the file.
      bResult = ::FtpGetFile(
         hFTPSession,
         InputSpec,
         OutputSpec,
         FALSE,
         FILE_ATTRIBUTE_NORMAL,
         FTP_TRANSFER_TYPE_BINARY,
         0);

      // Get next file.
      bResult = ::InternetFindNextFile(
                  hFileConnection,
                  &sWFD);
      }
   }

// Close connections.
InternetCloseHandle(hFileConnection);
InternetCloseHandle(hFTPSession);
InternetCloseHandle(hInternetSession);


#2


权限问题?
二进制/非二进制模式问题?
防火墙?
杀毒软件实时防护?
禁词过滤?
……?

#1


Linux 的不懂, Windows的 有  FtpGetFile


Creating a Synchronous Example
Suppose that you want to connect to an FTP server called ftp://ftp.infosite.com and copy all of the .ZIP files from its /BIN subdirectory to your local hard drive and store them in your C:\ZIPFILES subdirectory. The sample code might look like this:

HINTERNET hInternetSession;          // handle to internet connection
HINTERNET hFTPSession;               // handle to FTP session
HINTERNET hFileConnection;           // handle to file enumeration
WIN32_FIND_DATA sWFD;                // structure to hold FIND data
BOOL bResult = TRUE;                 // Boolean for return code
CString InputSpec;                   // variable to hold input spec
Cstring OutputSpec;                  // variable to hold output spec

hInternetSession = InternetOpen(
                  "Microsoft Internet Explorer",     // agent
                  INTERNET_OPEN_TYPE_PROXY,          // access
                  "ftp-gw",                          // proxy server
                  NULL,                              // defaults
                  0);                                // synchronous

// Make connection to ftp server.
hFTPSession = ::InternetConnect(
         hInternetSession,                // Handle from a previous
                                          // call to InternetOpen.
         "ftp://ftp.infosite.com",        // Server we want to connect to
         INTERNET_INVALID_PORT_NUMBER,    // Use appropriate port.
         NULL,                            // Use anonymous for username.
         NULL,                            // Use e-mail name for password
         INTERNET_SERVICE_FTP,            // Flag to use FTP services
         0,                               // Flags (see SDK docs)
         0);                              // Synchronous mode

// Find first .ZIP file.
hFileConnection = ::FtpFindFirstFile(
                    hFTPSession,
                    "*.ZIP",
                    &sWFD,
                    0,
                    0);
if (hFileConnection != (HINTERNET)NULL)
   {
   ::FtpSetCurrentDirectory(hFTPSession, "/BIN");

   while (bResult)
      {
      // Create file specs.
      InputSpec = "ftp://ftp.infosite.com/BIN/";
      InputSpec = InputSpec + sWFD.cFileName;
      OutputSpec = "c:\zipfiles\";
      OutputSpec = OutputSpec + sWFD.cFileName;

      // Transfer the file.
      bResult = ::FtpGetFile(
         hFTPSession,
         InputSpec,
         OutputSpec,
         FALSE,
         FILE_ATTRIBUTE_NORMAL,
         FTP_TRANSFER_TYPE_BINARY,
         0);

      // Get next file.
      bResult = ::InternetFindNextFile(
                  hFileConnection,
                  &sWFD);
      }
   }

// Close connections.
InternetCloseHandle(hFileConnection);
InternetCloseHandle(hFTPSession);
InternetCloseHandle(hInternetSession);


#2


权限问题?
二进制/非二进制模式问题?
防火墙?
杀毒软件实时防护?
禁词过滤?
……?