c#使用FTP协议将文件上传至unix主机
该程序原本是从windows主机A得到指定excel文档, 处理后发送邮件并上传至另一台Windows主机B, 现在主机B要变成Unix主机,并使用FTP协议,
我在程序里找到如下上传方法,应该是Windows主机的吧..., 请问大神如果变成上传至Unix主机要怎么写呢?谢谢各位大神!!
~~~~~~~~~~~调用上面Upload方法的地方~~~~~~~~~~~~~~~~`
我在程序里找到如下上传方法,应该是Windows主机的吧..., 请问大神如果变成上传至Unix主机要怎么写呢?谢谢各位大神!!
public string Upload(string FTPSubPath, string filename)
{
FileInfo fileInf = new FileInfo(filename);
string uri = "ftp://" + ftpServerIP + "/" + FTPSubPath + "/" + fileInf.Name;
FtpWebRequest reqFTP;
// Create FtpWebRequest object from the Uri provided
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
try
{
// Provide the WebPermission Credintials
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
reqFTP.Proxy = null; //当你的机子使用的是代理上网时,最好加上这一行,要不然报“使用 HTTP 代理时不支持请求的 FTP 命令。”错误
// By default KeepAlive is true, where the control connection is not closed
// after a command is executed.
reqFTP.KeepAlive = false;
// Specify the command to be executed.
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
// Specify the data transfer type.
reqFTP.UseBinary = true;
// Notify the server about the size of the uploaded file
reqFTP.ContentLength = fileInf.Length;
// The buffer size is set to 2kb
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;
// Opens a file stream (System.IO.FileStream) to read the file to be uploaded
//FileStream fs = fileInf.OpenRead();
FileStream fs = fileInf.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
// Stream to which the file to be upload is written
Stream strm = reqFTP.GetRequestStream();
// Read from the file stream 2kb at a time
contentLen = fs.Read(buff, 0, buffLength);
// Till Stream content ends
while (contentLen != 0)
{
// Write Content from the file stream to the FTP Upload Stream
strm.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
}
// Close the file stream and the Request Stream
strm.Close();
fs.Close();
return "ok";
}
catch (Exception ex)
{
reqFTP.Abort();
// Logging.WriteError(ex.Message + ex.StackTrace);
return ex.ToString() ;
}
}~~~~~~~~~~~调用上面Upload方法的地方~~~~~~~~~~~~~~~~`
if (attachFiles.Length > 0)
{
foreach (FileInfo attachName in oldFiles)
{
string rslt=ftpHelp_SPIL.Upload("/Jessie Test", attachName.Name);
if (rslt != "ok")
{
MailAbout.sendMail(strFrom, "SPILSZ", ini.Err_To, ini.Err_To, "FTP上传失败", ini.ErrSubject, sLocalOutputFilePath); ;
}
}
}
...全文
相关推荐
ftp文件操作
本文将围绕以下核心知识点展开讨论:FTP的基本概念、在Unix环境中使用FTP进行文件操作的方法以及通过编程实现FTP文件上传的示例。
C# Winform WPF 自动更新(基于FTP)
该项目实现了一个基于FTP的C#桌面应用程序自动更新功能,适用于WinForm和WPF架构。通过读取本地配置文件获取FTP地址与更新路径,结合黑名单机制过滤不需要更新的文件,并递归扫描本地文件生成可同
C#操作FTP服务器源码
本文将深入探讨如何使用C#进行FTP操作,并以提供的代码为基础,解析其关键功能。首先,让我们了解核心类`clsFTP`。
c# FTP操作类上传、异步上传文件、下载
- **FileListStyle枚举**:定义了文件列表的样式,包括Unix样式、Windows样式和未知样式。### 实现细节#### 文件上传文件上传是FTP操作中最常见的需求之一。
C#封装的完整FTP类
### C#封装的完整FTP类知识点解析#### 一、概述本文档介绍了一个使用C#语言封装的FTP客户端类库。该库旨在提供一系列针对FTP服务器的基本操作方法,包括但不限于文件上传、下载、列表查看等。


