Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by remymarathe · Feb 24, 2016 at 07:10 PM · serverconnectionhostftp

FTP Upload Files

Hello!

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Pratap-Dafedar · Feb 25, 2016 at 06:41 AM

Try this code snippets given in following link,

 /* Create Object Instance */
 ftp ftpClient = new ftp(@"ftp://10.10.10.10/", "user", "password");
 
 /* Upload a File */
 ftpClient.upload("etc/test.txt", @"C:\Users\metastruct\Desktop\test.txt");
 
 /* Download a File */
 ftpClient.download("etc/test.txt", @"C:\Users\metastruct\Desktop\test.txt");
 
 /* Delete a File */
 ftpClient.delete("etc/test.txt");
 
 /* Rename a File */
 ftpClient.rename("etc/test.txt", "test2.txt");
 
 /* Create a New Directory */
 ftpClient.createDirectory("etc/test");
 
 /* Get the Date/Time a File was Created */
 string fileDateTime = ftpClient.getFileCreatedDateTime("etc/test.txt");
 Console.WriteLine(fileDateTime);
 
 /* Get the Size of a File */
 string fileSize = ftpClient.getFileSize("etc/test.txt");
 Console.WriteLine(fileSize);
 
 /* Get Contents of a Directory (Names Only) */
 string[] simpleDirectoryListing = ftpClient.directoryListDetailed("/etc");
 for (int i = 0; i < simpleDirectoryListing.Count(); i++) { Console.WriteLine(simpleDirectoryListing[i]); }
 
 /* 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[i]); }
 /* Release Resources */
 ftpClient = null;


link here: http://www.codeproject.com/Tips/443588/Simple-Csharp-FTP-Class

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image yuriki · Jun 26, 2016 at 02:39 PM 2
Share

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, File$$anonymous$$ode.Create);

New/working string:

 FileStream localFileStream = new FileStream(localFile, File$$anonymous$$ode.Open);

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

avatar image sndsh07 · Aug 21, 2018 at 11:57 AM 0
Share

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

avatar image
0

Answer by Bunny83 · Feb 25, 2016 at 05:04 AM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Server closing after hide VDS window 0 Answers

Unity networking tutorial? 6 Answers

How connect client to server when ip is private ? 2 Answers

Networking Issue: Cannot connect to server 1 Answer

How to write/read .txt on FTP (Javascript) 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges