FTP Upload Files


I am trying to set up a very simple app that records some audio from the cellphone’s mic and sends the record to a FTP server. Everything is working fine, but the FTP connection. Any clues why is this happening? I read several forums but couldn’t make it work. Does it have anything to do with the syntax? “/”, “:”, and so on…? I keep getting this error:

UriFormatException: Invalid URI: The format of the URI could not be determined: ftp.Smarterasp.nettest.png System.Uri…ctor (System.String uriString, Boolean dontEscape)

Many thanks in advance! Here is the code:

public string m_FtpHost 	= "ftp://ftp.ftpserver.net/site1/trial";

	//public string filepath 	= "C:/Users/xxx/Desktop/24-02 09.32.32/test.png";

	public string m_FtpUsername = "user-001";

	public string m_FtpPassword = "xxx";

	public string filepath;

	public void UploadFile()

		// 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);

		Debug.Log (uri);

		// 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);


Try this code snippets given in following link,

/* Create Object Instance */
ftp ftpClient = new ftp(@"", "user", "password");

/* Upload a File */
ftpClient.upload("etc/test.txt", @"C:\Users\metastruct\Desktop	est.txt");

/* Download a File */
ftpClient.download("etc/test.txt", @"C:\Users\metastruct\Desktop	est.txt");

/* Delete a File */

/* Rename a File */
ftpClient.rename("etc/test.txt", "test2.txt");

/* Create a New Directory */

/* Get the Date/Time a File was Created */
string fileDateTime = ftpClient.getFileCreatedDateTime("etc/test.txt");

/* Get the Size of a File */
string fileSize = ftpClient.getFileSize("etc/test.txt");

/* Get Contents of a Directory (Names Only) */
string[] simpleDirectoryListing = ftpClient.directoryListDetailed("/etc");
for (int i = 0; i < simpleDirectoryListing.Count(); i++) { Console.WriteLine(simpleDirectoryListing*); }*

/* Get Contents of a Directory with Detailed File/Directory Info */
string[] detailDirectoryListing = ftpClient.directoryListDetailed(“/etc”);
for (int i = 0; i < detailDirectoryListing.Count(); i++) { Console.WriteLine(detailDirectoryListing*); }*
/* Release Resources */
ftpClient = null;
link here:
[Simple C# FTP Class - CodeProject][1]
_*[1]: Simple C# FTP Class - CodeProject

Well, you’re using a WebClient. A WebClient represents an HTTP client. FTP is an entirely different protocol. You need an actual FTP client. Something like FtpWebRequest which is part of the stock .NET classes or any other FTPClient implementation

Thank you Pratap Dafedar!

Everything work just fine.
But you need to change string (#80) for upload function in ftp class.
Old/wrong string:

FileStream localFileStream = new FileStream(localFile, FileMode.Create);

New/working string:

FileStream localFileStream = new FileStream(localFile, FileMode.Open);

In other case your file will be replaced with empty one.

Thank you @Pratap-Dafedar
file is successfully upload to ftp server but it loss packet at server machine it shows zero bytes please help me for this …
thank you so much