ftpwebrequest

System.Net.FtpWebRequest GetDateTimestamp example

十年热恋 提交于 2019-11-26 17:51:50
问题 I'm looking for a short bit of sample code which uses the System.Net.FtpWebRequest namespace to get the timestamp of a specified remote file on an ftp server. I know I need to set the Method property of my request object to WebRequestMethods.Ftp.GetDateTimestamp but I'm not sure how to get the response back into a System.DateTime object. 回答1: Yep - thats pretty much what I ended up with. I went with something like this request = FtpWebRequest.Create("ftp://ftp.whatever.com/somefile.txt");

Retrieving creation date of file (FTP)

a 夏天 提交于 2019-11-26 16:39:14
I'm using the System.Net.FtpWebRequest class and my code is as follows: FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://example.com/folder"); request.Method = WebRequestMethods.Ftp.ListDirectory; request.Credentials = new NetworkCredential("username", "password"); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); Stream responseStream = response.GetResponseStream(); StreamReader reader = new StreamReader(responseStream); string names = reader.ReadToEnd(); reader.Close(); response.Close(); This is based off of the examples provided on MSDN but I couldn't find

How to check if an FTP Directory Exists

守給你的承諾、 提交于 2019-11-26 16:13:14
问题 Looking for the best way to check for a given directory via FTP. Currently i have the following code: private bool FtpDirectoryExists(string directory, string username, string password) { try { var request = (FtpWebRequest)WebRequest.Create(directory); request.Credentials = new NetworkCredential(username, password); request.Method = WebRequestMethods.Ftp.GetDateTimestamp; FtpWebResponse response = (FtpWebResponse)request.GetResponse(); } catch (WebException ex) { FtpWebResponse response =

How to check if file exists on FTP before FtpWebRequest

北慕城南 提交于 2019-11-26 14:30:20
I need to use FtpWebRequest to put a file in a FTP directory. Before the upload, I would first like to know if this file exists. What method or property should I use to check if this file exists? var request = (FtpWebRequest)WebRequest.Create ("ftp://ftp.domain.com/doesntexist.txt"); request.Credentials = new NetworkCredential("user", "pass"); request.Method = WebRequestMethods.Ftp.GetFileSize; try { FtpWebResponse response = (FtpWebResponse)request.GetResponse(); } catch (WebException ex) { FtpWebResponse response = (FtpWebResponse)ex.Response; if (response.StatusCode == FtpStatusCode

Howto do a simple ftp get file on Android

帅比萌擦擦* 提交于 2019-11-26 12:29:29
问题 I can\'t find an example of a simple FTP access of a file anywhere, and the FTPClient class (which a couple of examples use) doesn\'t appear in the Android Class Index. I\'ve got http access working, but how do I do a simple FTP get? All I want to do is download (for example): ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/KABQ.TXT It shouldn\'t require login, change directory, etc. Just giving that URL to the http access methods don\'t seem to work. This is similar to the question

Parsing FtpWebRequest ListDirectoryDetails line

时光怂恿深爱的人放手 提交于 2019-11-26 11:23:33
I need some help with parsing the response from ListDirectoryDetails in C#. I only need the following fields. File Name/Directory Name Date Created and the File Size. Here's what some of the lines look like when I run ListDirectoryDetails : d--x--x--x 2 ftp ftp 4096 Mar 07 2002 bin -rw-r--r-- 1 ftp ftp 659450 Jun 15 05:07 TEST.TXT -rw-r--r-- 1 ftp ftp 101786380 Sep 08 2008 TEST03-05.TXT drwxrwxr-x 2 ftp ftp 4096 May 06 12:24 dropoff Thanks in advance. Not sure if you still need this, but this is the solution i came up with: Regex regex = new Regex ( @"^([d-])([rwxt-]{3}){3}\s+\d{1,}\s+.*?(\d{1

Upload file on FTP

风格不统一 提交于 2019-11-26 11:06:24
问题 I want to upload file from one server to another FTP server and following is my code to upload file but it is throwing an error as: The remote server returned an error: (550) File unavailable (e.g., file not found, no access). This my code: string CompleteDPath = \"ftp URL\"; string UName = \"UserName\"; string PWD = \"Password\"; WebRequest reqObj = WebRequest.Create(CompleteDPath + FileName); reqObj.Method = WebRequestMethods.Ftp.UploadFile; reqObj.Credentials = new NetworkCredential(UName,

C# class to parse WebRequestMethods.Ftp.ListDirectoryDetails FTP response

南楼画角 提交于 2019-11-26 10:36:24
I'm creating a service to monitor FTP locations for new updates and require the ability to parse the response returned from a FtpWebRequest response using the WebRequestMethods.Ftp.ListDirectoryDetails method. It would be fairly easy if all responses followed the same format, but different FTP server software provide different response formats. For example one might return: 08-10-11 12:02PM <DIR> Version2 06-25-09 02:41PM 144700153 image34.gif 06-25-09 02:51PM 144700153 updates.txt 11-04-10 02:45PM 144700214 digger.tif And another server might return: d--x--x--x 2 ftp ftp 4096 Mar 07 2002 bin

Upload file and download file from FTP

旧街凉风 提交于 2019-11-26 09:55:24
问题 I am trying to make a program that uploads/downloads .exe file to a FTP I tried using FtpWebRequest , but I only succeed to upload and download .txt files. Then i found here a solution for downloading using the WebClient : WebClient request = new WebClient(); request.Credentials = new NetworkCredential(\"username\", \"password\"); byte[] fileData = request.DownloadData(\"ftp://myFTP.net/\"); FileStream file = File.Create(destinatie); file.Write(fileData, 0, fileData.Length); file.Close();

Does .NET FtpWebRequest Support both Implicit (FTPS) and explicit (FTPES)?

房东的猫 提交于 2019-11-26 08:14:53
问题 I am being asked to support implicit and explicit FTPS (also known as FTPES). We are currently using the .NET FtpWebRequest . Does the FtpWebRequest support both types of FTPES, and what is the difference? Thanks 回答1: as far as I know the current (.NET 2.0 and 3.5) version of FtpWebRequest supports Explicit SSL only. Actually, .NET 2.0 does not currently support implicit SSL, only explicit. We will consider adding this for a future release. JonCole - MSFTModerator at MSDN forum post If you