-->Inheritance
Definition
Can someone provide a small sample in c# that uses FtpWebRequest to download files asynchronously from an FPT server?? I have the full path of the files to be downloaded from the ftp server, and I need to use 1 connection to start downloading to my local machine asynchronously, so I dont need to go file by file and open/close connection for. FTP client library for C#, including asynchronous operations. I've tried to use your FTP Client class in a small windows service application that periodically checks a local ftp server and downloads new files.
The asynchronous version seems to complete FTP uploads twice as fast as the non-asynchronous version. This makes me think that the synchrony being manipulated here is more than just that between a UI thread and a worker thread in the C# code. Ultimate FTP library written 100% in C# makes it easy to upload, download and manage files and folders right in your apps. With intuitive API and supports for unsecure and secure TLS SSL servers, it helps you create.NET FTP clients in minutes. Robust.NET FTP/SSL Library for C# & VB.NET. Ultimate FTP.NET class library lets you add the.
MarshalByRefObjectMarshalByRefObjectMarshalByRefObjectMarshalByRefObject
FtpWebRequestFtpWebRequestFtpWebRequestFtpWebRequestExamples
The following code example demonstrates deleting a file from an FTP server.
The following code example demonstrates downloading a file from an FTP server by using the WebClient class.
The following code example demonstrates using asynchronous operations to upload a file to an FTP server.
In the United States and elsewhere. Unreal, the circle-U logo and the Powered by Unreal Technology logo are trademarks or registered trademarks of Epic Games, Inc. Uses Bink Video. Borderlands 2 goty mac. 2K Games and the 2K Games logo are trademarks of 2K Games in the US and/or other countries.
Remarks
Important
We don't recommend that you use the
FtpWebRequest
class for new development. For more information and alternatives to FtpWebRequest
, see WebRequest shouldn't be used on GitHub. To obtain an instance of FtpWebRequest, use the Create method. You can also use the WebClient class to upload and download information from an FTP server. Using either of these approaches, when you specify a network resource that uses the FTP scheme (for example,
'ftp://contoso.com'
) the FtpWebRequest class provides the ability to programmatically interact with FTP servers. The URI may be relative or absolute. If the URI is of the form
'ftp://contoso.com/%2fpath'
(%2f is an escaped '/'), then the URI is absolute, and the current directory is /path
. If, however, the URI is of the form 'ftp://contoso.com/path'
, first the .NET Framework logs into the FTP server (using the user name and password set by the Credentials property), then the current directory is set to <UserLoginDirectory>/path
. You must have a valid user name and password for the server or the server must allow anonymous logon. You can specify the credentials used to connect to the server by setting the Credentials property or you can include them in the UserInfo portion of the URI passed to the Create method. If you include UserInfo information in the URI, the Credentials property is set to a new network credential with the specified user name and password information.
Caution
Unless the EnableSsl property is
true
, all data and commands, including your user name and password information, are sent to the server in clear text. Anyone monitoring network traffic can view your credentials and use them to connect to the server. If you are connecting to an FTP server that requires credentials and supports Secure Sockets Layer (SSL), you should set EnableSsl to true
. You must have WebPermission to access the FTP resource; otherwise, a SecurityException exception is thrown.
Specify the FTP command to send to the server by setting the Method property to a value defined in the WebRequestMethods.Ftp structure. To transmit text data, change the UseBinary property from its default value (
true
) to false
. For details and restrictions, see Method. When using an FtpWebRequest object to upload a file to a server, you must write the file content to the request stream obtained by calling the GetRequestStream method or its asynchronous counterparts, the BeginGetRequestStream and EndGetRequestStream methods. You must write to the stream and close the stream before sending the request.
Requests are sent to the server by calling the GetResponse method or its asynchronous counterparts, the BeginGetResponse and EndGetResponse methods. When the requested operation completes, an FtpWebResponse object is returned. The FtpWebResponse object provides the status of the operation and any data downloaded from the server.
You can set a time-out value for reading or writing to the server by using the ReadWriteTimeout property. If the time-out period is exceeded, the calling method throws a WebException with WebExceptionStatus set to Timeout.
When downloading a file from an FTP server, if the command was successful, the contents of the requested file are available in the response object's stream. You can access this stream by calling the GetResponseStream method. For more information, see FtpWebResponse.
If the Proxy property is set, either directly or in a configuration file, communications with the FTP server are made through the specified proxy. If the specified proxy is an HTTP proxy, only the DownloadFile, ListDirectory, and ListDirectoryDetails commands are supported.
Only downloaded binary content is cached; that is, content received using the DownloadFile command with the UseBinary property set to
true
. Multiple FtpWebRequests reuse existing connections, if possible.
For more information about the FTP protocol, see RFC 959: File Transfer Protocol.
Asynchronous C# Tutorial
Properties
AuthenticationLevelAuthenticationLevelAuthenticationLevelAuthenticationLevel | Gets or sets values indicating the level of authentication and impersonation used for this request. (Inherited from WebRequest) |
CachePolicyCachePolicyCachePolicyCachePolicy | Gets or sets the cache policy for this request. (Inherited from WebRequest) |
ClientCertificatesClientCertificatesClientCertificatesClientCertificates | Gets or sets the certificates used for establishing an encrypted connection to the FTP server. |
ConnectionGroupNameConnectionGroupNameConnectionGroupNameConnectionGroupName | Gets or sets the name of the connection group that contains the service point used to send the current request. |
ContentLengthContentLengthContentLengthContentLength | Gets or sets a value that is ignored by the FtpWebRequest class. |
ContentOffsetContentOffsetContentOffsetContentOffset | Gets or sets a byte offset into the file being downloaded by this request. |
ContentTypeContentTypeContentTypeContentType | Always throws a NotSupportedException. |
CreatorInstanceCreatorInstanceCreatorInstanceCreatorInstance | When overridden in a descendant class, gets the factory object derived from the IWebRequestCreate class used to create the WebRequest instantiated for making the request to the specified URI. (Inherited from WebRequest) |
CredentialsCredentialsCredentialsCredentials | Gets or sets the credentials used to communicate with the FTP server. |
DefaultCachePolicyDefaultCachePolicyDefaultCachePolicyDefaultCachePolicy | Defines the default cache policy for all FTP requests. |
EnableSslEnableSslEnableSslEnableSsl | Gets or sets a Boolean that specifies that an SSL connection should be used. |
HeadersHeadersHeadersHeaders | Gets an empty WebHeaderCollection object. |
ImpersonationLevelImpersonationLevelImpersonationLevelImpersonationLevel | Gets or sets the impersonation level for the current request. (Inherited from WebRequest) |
KeepAliveKeepAliveKeepAliveKeepAlive | Gets or sets a Boolean value that specifies whether the control connection to the FTP server is closed after the request completes. |
MethodMethodMethodMethod | Gets or sets the command to send to the FTP server. |
PreAuthenticatePreAuthenticatePreAuthenticatePreAuthenticate | Always throws a NotSupportedException. |
ProxyProxyProxyProxy | Sony vegas studio 11. Gets or sets the proxy used to communicate with the FTP server. |
ReadWriteTimeoutReadWriteTimeoutReadWriteTimeoutReadWriteTimeout | Gets or sets a time-out when reading from or writing to a stream. |
RenameToRenameToRenameToRenameTo | Gets or sets the new name of a file being renamed. |
RequestUriRequestUriRequestUriRequestUri | Gets the URI requested by this instance. |
ServicePointServicePointServicePointServicePoint | Gets the ServicePoint object used to connect to the FTP server. |
TimeoutTimeoutTimeoutTimeout | Gets or sets the number of milliseconds to wait for a request. |
UseBinaryUseBinaryUseBinaryUseBinary | Gets or sets a Boolean value that specifies the data type for file transfers. |
UseDefaultCredentialsUseDefaultCredentialsUseDefaultCredentialsUseDefaultCredentials | Always throws a NotSupportedException. |
UsePassiveUsePassiveUsePassiveUsePassive | Gets or sets the behavior of a client application's data transfer process. |
Methods
Abort()Abort()Abort()Abort() | Terminates an asynchronous FTP operation. |
BeginGetRequestStream(AsyncCallback, Object)BeginGetRequestStream(AsyncCallback, Object)BeginGetRequestStream(AsyncCallback, Object)BeginGetRequestStream(AsyncCallback, Object) | Begins asynchronously opening a request's content stream for writing. |
BeginGetResponse(AsyncCallback, Object)BeginGetResponse(AsyncCallback, Object)BeginGetResponse(AsyncCallback, Object)BeginGetResponse(AsyncCallback, Object) | Begins sending a request and receiving a response from an FTP server asynchronously. |
CreateObjRef(Type)CreateObjRef(Type)CreateObjRef(Type)CreateObjRef(Type) | Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject) |
EndGetRequestStream(IAsyncResult)EndGetRequestStream(IAsyncResult)EndGetRequestStream(IAsyncResult)EndGetRequestStream(IAsyncResult) | Ends a pending asynchronous operation started with BeginGetRequestStream(AsyncCallback, Object). |
EndGetResponse(IAsyncResult)EndGetResponse(IAsyncResult)EndGetResponse(IAsyncResult)EndGetResponse(IAsyncResult) | Ends a pending asynchronous operation started with BeginGetResponse(AsyncCallback, Object). |
Equals(Object)Equals(Object)Equals(Object)Equals(Object) | Determines whether the specified object is equal to the current object. (Inherited from Object) |
GetHashCode()GetHashCode()GetHashCode()GetHashCode() | Serves as the default hash function. (Inherited from Object) |
GetLifetimeService()GetLifetimeService()GetLifetimeService()GetLifetimeService() | Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject) |
GetObjectData(SerializationInfo, StreamingContext)GetObjectData(SerializationInfo, StreamingContext)GetObjectData(SerializationInfo, StreamingContext)GetObjectData(SerializationInfo, StreamingContext) | Populates a SerializationInfo with the data needed to serialize the target object. (Inherited from WebRequest) |
GetRequestStream()GetRequestStream()GetRequestStream()GetRequestStream() | Retrieves the stream used to upload data to an FTP server. |
GetRequestStreamAsync()GetRequestStreamAsync()GetRequestStreamAsync()GetRequestStreamAsync() | When overridden in a descendant class, returns a Stream for writing data to the Internet resource as an asynchronous operation. (Inherited from WebRequest) |
GetResponse()GetResponse()GetResponse()GetResponse() | Returns the FTP server response. |
GetResponseAsync()GetResponseAsync()GetResponseAsync()GetResponseAsync() | When overridden in a descendant class, returns a response to an Internet request as an asynchronous operation. (Inherited from WebRequest) |
GetType()GetType()GetType()GetType() | Gets the Type of the current instance. (Inherited from Object) |
InitializeLifetimeService()InitializeLifetimeService()InitializeLifetimeService()InitializeLifetimeService() | Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject) |
MemberwiseClone()MemberwiseClone()MemberwiseClone()MemberwiseClone() | Creates a shallow copy of the current Object. (Inherited from Object) |
MemberwiseClone(Boolean)MemberwiseClone(Boolean)MemberwiseClone(Boolean)MemberwiseClone(Boolean) | Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject) |
ToString()ToString()ToString()ToString() | Returns a string that represents the current object. (Inherited from Object) |
Ftp Download Sites
Explicit Interface Implementations
ISerializable.GetObjectData(SerializationInfo, StreamingContext)ISerializable.GetObjectData(SerializationInfo, StreamingContext)ISerializable.GetObjectData(SerializationInfo, StreamingContext)ISerializable.GetObjectData(SerializationInfo, StreamingContext) | When overridden in a descendant class, populates a SerializationInfo instance with the data needed to serialize the WebRequest. (Inherited from WebRequest) |
Ftp Download Software
Security
Asynchronous C# Example
WebPermission
for accessing the resource referenced by this request. Associated enumeration: Connect.
for accessing the resource referenced by this request. Associated enumeration: Connect.
Applies to
See also
- WebRequestWebRequestWebRequestWebRequest
- WebResponseWebResponseWebResponseWebResponse