我正在使用以下代码从远程FTP服务器下载文件:
```python import ftplib
ftp = ftplib.FTP('hostname') ftp.login('username', 'password') ftp.cwd('/remote_dir/') with open('local_file', 'wb') as f: ftp.retrbinary('RETR remote_file', f.write) ftp.quit() ```
这个代码使用Python的ftplib库连接到FTP服务器,登录并进入远程目录。然后,它使用`retrbinary()`方法以二进制模式检索远程文件,并将其写入本地文件。最后,关闭FTP连接。
有人能提供任何关于可能出了什么问题的想法吗?
```python import ftplib
ftp = ftplib.FTP('hostname') ftp.login('username', 'password') ftp.cwd('/remote_dir/') with open('local_file', 'wb') as f: ftp.retrbinary('RETR remote_file', f.write) ftp.quit() ```
这个代码使用Python的ftplib库连接到FTP服务器,登录并进入远程目录。然后,它使用`retrbinary()`方法以二进制模式检索远程文件,并将其写入本地文件。最后,关闭FTP连接。
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverPath);
request.KeepAlive = true;
request.UsePassive = true;
request.UseBinary = true;
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential(userName, password);
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
using (Stream responseStream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(responseStream))
using (StreamWriter destination = new StreamWriter(destinationFile))
{
destination.Write(reader.ReadToEnd());
destination.Flush();
}
我正在下载的文件是一个dll文件,我的问题是它被这个进程以某种方式修改了。我知道这是因为文件大小在增加。我怀疑代码的这一部分有问题:
destination.Write(reader.ReadToEnd());
destination.Flush();
有人能提供任何关于可能出了什么问题的想法吗?