Hi all!
I’m currently working on a project where I upload files in my ftp server. I’m stuck in the part where I have to retrieve the file path of the uploaded file.
Here is my code for calling my ftp function
void Start () {
/* Create Object Instance */
ftp ftpClient = new ftp(ftpURL, username, password);
/* Upload a File */
ftpClient.uploadimage("test_photos/test_image.jpg", Application.dataPath + "/StreamingAssets/test.jpg");
}
and here is the code i have for uploading
/* Upload Image */
public void uploadimage(string remoteFile, string localFile)
{
try
{
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(host + "/" + remoteFile);
ftpRequest.UseBinary = true;
ftpRequest.UsePassive = true;
ftpRequest.KeepAlive = true;
ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
ftpRequest.Credentials = new NetworkCredential(user, pass);
byte[] fileData = File.ReadAllBytes(localFile);
ftpRequest.ContentLength = fileData.Length;
Stream reqStream = ftpRequest.GetRequestStream();
reqStream.Write(fileData, 0, fileData.Length);
reqStream.Close();
ftpRequest = null;
Debug.Log("Image uploaded.");
}
catch (Exception ex) { Debug.Log(ex.ToString()); }
return;
}
I can upload image to my FTP server without any problem. However, I want to get the link of that uploaded file. Any help would be greatly appreciated. Thanks.