Tag: ftpwebrequest

c#ftp上传到Linux

我试图检查FTP服务器上是否存在目录。 在你说“使用ListDirectory”或“使用PrintWorkingDirectory”之前,它们并不总是有用; 例如,我测试了ftp:// webserver / Logs是否存在,并且两者都告诉我它实际上并没有。 所以我沿着将文件上传到目录的路线,如果成功,那么目录就存在了。 问题是,下面的方法不适用于GoDaddy的基于CentOS的服务器运行vsFTPd 2.0.7.2。 适用于IIS7.5上的Microsoft FTP服务器。 因此,我使用Wireshark监控流量,并使用Filezilla查看我的应用程序无法使其正常运行。 唯一的区别是Filezilla正在更改工作目录,因为我正在尝试使用之前的路径上传文件。 我感觉它与上传到服务器的路径和Linux的解释有关,因为它可能有点有趣的名字…… :-D任何想法热烈欢迎? 应用代码 private bool DirectoryExists(string d) { bool exists = true; try { string file = “directoryexists.test”; string path = url + homepath + d + “/” + file; //Try to save to the directory req = (FtpWebRequest)WebRequest.Create(path); req.ConnectionGroupName = “conngroup1”; […]

如何使用c#通过FTP下载压缩文件(.zip)?

如何使用c#代码下载.zip文件格式? 这是代码,我用来下载。 只是为了突出显示,如果我下载.txt文件,它工作正常。 如果我下载.zip文件,它会下载.zip文件,但我无法打开它。 它抱怨.zip的格式不正确。 我怀疑我如何在本地驱动器上写回文件。 救命? string ftpServerIP = FTPServer; string ftpUserID = FTPUser; string ftpPassword = FTPPwd; FileInfo fileInf = new FileInfo(FileName); string uri = “ftp://” + ftpServerIP + “/” + fileInf.Name; FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(uri); //new Uri(“ftp://” + ftpServerIP + DestinationFolder + fileInf.Name)); reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword); reqFTP.EnableSsl = true; reqFTP.KeepAlive […]

.Net FtpWebRequest有时会失败

我尝试使用FtpWebRequest列出文件详细信息但很常见它因WebException而失败并显示错误530用户未登录。 这怎么可能,它在某些时候使用相同的凭据工作? 摘自代码: reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpuri)); reqFTP.UseBinary = true; reqFTP.Credentials = new NetworkCredential(userName, password); string[] downloadFiles = new string[0]; reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails; WebResponse response = reqFTP.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); downloadFiles = reader.ReadToEnd().Replace(“\r\n”, “¤”).Split(‘¤’); reader.Close(); response.Close();

FTP上载文件使用HTTP代理时不支持请求的FTP命令

有人可以看看下面的代码并告诉我我做错了什么。 我只是在圈子里,任何指针都非常感激 public class FtpWebRequestUtil { private static string RemoteHost; private static string RemoteFtpPath; public static NetworkCredential Credential = new NetworkCredential(); public FtpWebRequestUtil() { } public FtpWebRequestUtil(string RemoteAddress, string RemotePath, string RemoteUser, string RemotePwd) { Credential.UserName = RemoteUser; Credential.Password = RemotePwd; RemoteHost = RemoteAddress; RemoteFtpPath = RemotePath; } public string UploadFile(string localFilePath) { int startTime […]

使用C#将可流式内存文档(.docx)上传到FTP?

我正在尝试将MemoryStream的.docx文件上传到FTP 但是上传完成后,文件为空。 MemoryStream mms = new MemoryStream(); document2.SaveToStream(mms, Spire.Doc.FileFormat.Docx); string ftpAddress = “example”; string username = “example”; string password = “example”; using (StreamReader stream = new StreamReader(mms)) { // adnu is a random file name. WebRequest request = WebRequest.Create(“ftp://” + ftpAddress + “/public_html/b/” + adnu + “.docx”); request.Method = WebRequestMethods.Ftp.UploadFile; request.Credentials = new NetworkCredential(username, password); […]

检查FTP上是否存在文件 – 不知道文件的名称

我在FTP服务器上收到一个文件,该文件的名称是动态生成的。 我正在尝试编写一个程序来检查服务器上是否存在任何文件。 string userName = Dts.Variables[“User::SFTPUsername”].Value.ToString(); string password = Dts.Variables[“User::SFTPPassword”].Value.ToString(); **string fileName = Dts.Variables[“User::FilePattern”].Value.ToString();** string ftpURL = String.Format(“ftp://11.11.11/upload/{0}”, fileName); WebClient request = new WebClient(); request.Credentials = new NetworkCredential(userName, password); FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(ftpURL); ftpRequest.Method = WebRequestMethods.Ftp.GetFileSize; ftpRequest.Credentials = new NetworkCredential(userName, password); using (FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse()) { byte[] newFileData = request.DownloadData(ftpURL.ToString()); string fileString = System.Text.Encoding.UTF8.GetString(newFileData); […]

从FTP服务器下载新文件和修改过的文件

我正在尝试获取FTP服务器上的文件列表,然后逐一检查本地系统上是否存在该文件,是否确实比较了修改日期以及ftp文件是否更新下载它。 private void btnGo_Click(object sender, EventArgs e) { string[] files = GetFileList(); foreach (string file in files) { if (file.Length >= 5) { string uri = “ftp://” + ftpServerIP + “/” + remoteDirectory + “/” + file; Uri serverUri = new Uri(uri); CheckFile(file); } } this.Close(); } public string[] GetFileList() { string[] downloadFiles; StringBuilder result […]

使用FtpWebRequest上传文件时获取“无效的URL”

我们有一个OpenVMS(VMS)Alpha服务器,我需要访问它才能通过FTP传输文件。 问题是它在启动连接时不支持FtpWebRequest使用的命令( ftp://192.168.xx.xx ),除了FtpWebRequest之外还有其他任何我可以使用的FTPfunction吗? 之前我一直在Windows和Unix环境中使用我的代码,但这是我第一次在VMS操作系统上执行此操作,我也可以使用命令提示符通过FTP访问服务器。 以下是我的代码: //Initializing ftp request ftp ftpClient = new ftp(@”ftp://192.168.xx.xx/”, “username”, “password”); MessageBox.Show((ftpClient.upload(“FILE.TAB”, @”C:\FILE.TAB”)).ToString()); public ftp(string hostIP, string userName, string password) { host = hostIP; user = userName; pass = password; } public string upload(string remoteFile, string localFile) { try { /* Create an FTP Request */ ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host + […]

FtpWebRequest ListDirectory不返回隐藏文件

使用FtpWebRequest列出目录的内容; 但是,它没有显示隐藏文件。 如何让它显示隐藏文件? FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftp_root + path); request.Method = WebRequestMethods.Ftp.ListDirectory; FileZilla正确列出了隐藏文件,因此我知道FTP服务器正在将数据返回给它。 我只需要用FtpWebRequest复制它。 或者使用不同的库。

FtpWebRequest错误:550 ASCII模式下不允许使用大小

我试图通过匿名FTP从远程FTP文件中获取文件大小。 public static long GetSize(string ftpPath) { try { FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpPath)); request.Proxy = null; request.Credentials = new NetworkCredential(“anonymous”, “´”); request.UseBinary = true; request.Method = WebRequestMethods.Ftp.GetFileSize; FtpWebResponse response = (FtpWebResponse)request.GetResponse(); long size = response.ContentLength; response.Close(); return size; } catch (WebException e) { string status = ((FtpWebResponse)e.Response).StatusDescription; MessageBox.Show(status); return 0; } } 这当前返回错误“550 ASCII模式下不允许的大小”。 […]