File upload 二进制文件的FTP上载

File upload 二进制文件的FTP上载,file-upload,ftp,binary,File Upload,Ftp,Binary,到目前为止,我可以上传一些文件到我的服务器使用以下代码,你能帮我改变这个代码上传二进制文件吗?谢谢 // Get the object used to communicate with the server. FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://sosoft.com/AES.file"); request.Method = WebRequestMethods.Ftp.UploadFile; requ

到目前为止,我可以上传一些文件到我的服务器使用以下代码,你能帮我改变这个代码上传二进制文件吗?谢谢

// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://sosoft.com/AES.file");

request.Method = WebRequestMethods.Ftp.UploadFile;


request.Credentials = new NetworkCredential("user.com", "xxxwALpH@J1rW"); 
// Copy the contents of the file to the request stream.

StreamReader sourceStream = new StreamReader("AES.file");
byte [] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close(); 
request.ContentLength = fileContents.Length;


Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();

FtpWebResponse response = (FtpWebResponse)request.GetResponse();    
Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

response.Close();

ftp
是70年代(1970!)的协议。这对所有管理员和安全人员来说都是一场噩梦。而且它需要各种特殊处理(就像你的情况一样)。你确定没有像
sftp
rsync
这样的明智选择吗?谢谢你。在c#中如何使用sftp?对不起,我不知道c#,它在微软Windows世界之外的实际应用并不多。但我假设有一个ssh库可用,因为它应该提供网络逻辑。sftp是ssh的一个子策略,因此它应该得到此类库的支持。检查文档,我会说。不用担心,谢谢你,让它能够处理像这样的代码:string PureFileName=newfileinfo(fileName).Name;String uploadUrl=String.Format(“{0}{1}/{2}”,FtpUrl,UploadDirectory,PureFileName);FtpWebRequest请求=(FtpWebRequest)FtpWebRequest.Create(上传URL);req.Proxy=null;req.Method=WebRequestMethods.Ftp.UploadFile;请求凭证=新的网络凭证(用户名、密码);req.UseBinary=true;req.USEANSACTIVE=真;好的但请记住,这样传输的所有数据都是完全未加密的,并且要求防火墙规则在所有端口上都非常开放。您确实希望切换到更现代、更方便的sftp协议。