snake plissken
snake plissken

Reputation: 2669

All rising exceptions when uploading a file to the server

I am using the following function in order to send to a server data from Unity project:

public void UploadFile(string filepath)
{
 // Get an instance of WebClient
 WebClient client = new System.Net.WebClient();
 // parse the ftp host and file into a uri path for the upload
 Uri uri = new Uri(m_FtpHost + new FileInfo(filepath).Name);
 // set the username and password for the FTP server
 client.Credentials = new System.Net.NetworkCredential(m_FtpUsername, m_FtpPassword);
 // upload the file asynchronously, non-blocking.
 client.UploadFileAsync(uri, "STOR", filepath);
}

What I want is to find all the possible exception that I could catch when I am uploading files to a server. Is there any list or tutorial about that? EDIT: two important issues I want to handle is internet connection and problems with storage (insufficient space).

Upvotes: 0

Views: 752

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460148

Isn't it documented in the method that you're using, WebClient.UploadFileAsync?

Exceptions

  • ArgumentNullException: The address parameter is null -or- The fileName parameter is null.
  • WebException: The URI formed by combining BaseAddress and address is invalid. -or- fileName is null, is Empty, contains invalid character, or the specified path to the file does not exist. -or- An error occurred while opening the stream. -or- There was no response from the server hosting the resource. -or- The Content-type header begins with multipart.

The WebException.Statusis set to indicate the error.

Upvotes: 2

Related Questions