[Resolved] FTP - Error uploading file

Hi all,
I have a problem uploading files with FTP. My code works perfectly from the simulator and upload the picture called “Icon-small.png” (12k), but when I transfer my app to iPhone4 (and iPad1) and I do run … indicates error uploading the file. Interestingly the file is uploaded, but the size is 0k (zero).
What am I doing wrong?

I have updated the latest corona and XCode version (20-oct-2012).

Corona SDK: 2012.935
XCode: 4.5.1

iPhone 4 : iOS 6
iPad1 : iOS 5.1.1

 ftp = require("ftp")  
  
 connection = ftp.newConnection{   
 host = "ftp.dominio.com",   
 user = "userName",   
 password = "clave",   
 port = 21   
 }  
  
 function onError()  
 print("Error")   
 end  
  
 function onUploadSuccess()  
 print("Upload ok")  
 end  
  
 connection:upload{  
 localFile = "Icon-Small.png",  
 remoteFile = "/dominio.com/upload/Icon-Small.png",  
 onSuccess = onUploadSuccess,  
 onError = onError  
 }  

can you help me? @peach can you?

@rycott

[import]uid: 121547 topic_id: 32147 reply_id: 332147[/import]

I can’t be sure without testing your code, but this sounds suspiciously like the case-sensitive file issue between Simulator and device, where (I think) the Simulator isn’t demanding of a case-sensitive file name, but the device IS picky about it. I can’t vouch for that (somebody want to confirm?) but it seems like something I read recently while skimming the forums.

Brent [import]uid: 9747 topic_id: 32147 reply_id: 128047[/import]

mmm, i try with simple “dog.png” and “dog.txt” and not working…

localFile = "dog.png",  
remoteFile = "/dominio.com/upload/dog.png",  

and

localFile = "dog.txt",  
remoteFile = "/dominio.com/upload/dog.txt",  

Help me…
do you have some example? @peach, any help??

Thanks
[import]uid: 121547 topic_id: 32147 reply_id: 128184[/import]

I can’t be sure without testing your code, but this sounds suspiciously like the case-sensitive file issue between Simulator and device, where (I think) the Simulator isn’t demanding of a case-sensitive file name, but the device IS picky about it. I can’t vouch for that (somebody want to confirm?) but it seems like something I read recently while skimming the forums.

Brent [import]uid: 9747 topic_id: 32147 reply_id: 128047[/import]

Does the directory:

/domino.com

exist on the ftp server? What about the directory:

/domino.com/upload

??? Does the username userName have write access to the upload directory?

I’ve never used the ftp library before, so forgive my ignorance? What folder does Icon-Small.png or dog.png exist in? Is it in the system.ResourcesDirectory (where your main.lua file is)? Is it in the system.DocumentsDiretory or the system.CachesDirectory? Which folder does the ftp app look at to begin with? For instance if its looking in system.DocumentsDirectory (a logical place for your app to write files too) and you’re Icon-Small.png lives in the Resource Bundle, I don’t see anything above to tell FTP were to find the image at.
EDIT**** I may have answered some of my own questions. It looks like you are trying to use Graham Ransom’s ftp helper from the community code. If thats the case, then this is the syntax to upload a file:

connection:upload{  
 localFile = system.pathForFile("image.jpg", system.ResourcesDirectory),  
 remoteFile = "/public\_html/image.jpg",  
 onSuccess = onUploadSuccess,  
 onError = onError  
)  

Note the line that reads:

system.pathForFile(“image.jpg”, system.ResourcesDirectory),

This is critical as your app runs in a sandbox, this is how you file files and give the app a path to find it. In this case, if your Icon-small.png is in the resource bundle (same folder as main.lua) then you would do:

localFile = system.pathForFile("Icon-small.png", system.ResourcesDirectory),  

If the file dog.png lives outside the resource bundle, say something you created with io.write or something saved by one of the photo saving tools, its like to be in the DocumentsDirectory

localFile = system.pathForFile("dog.png", system.DocumentsDirectory),  

without this system.pathForFile() call you’re not going to find the file to upload.
[import]uid: 19626 topic_id: 32147 reply_id: 128195[/import]

Hi robmiracle,
i try…

“Icon-small.png” (and dog.png) is same folder as main.lua
localFile = system.pathForFile(“Icon-small.png”, system.ResourcesDirectory),

and the new file
gato.txt is in documents…
localFile = system.pathForFile(“gato.txt”, system.DocumentsDirectory),

in corona simulator work ok, but iPhone send the file via FTP to my server with the same name and extension (“gato.txt” or “Icon-small.png”) but have a size of zero k. both throw errors when opened. Besides the message indicating the FTP function is ERROR.

therefore rule out that the problem is with the sending of the file, and I did a test by placing a fictitious name to send and the system upload this file Likewise ghost zero size k. I gather then that the problem is that the app loaded on your iPhone or iPad can not find the ORIGINAL.
[import]uid: 121547 topic_id: 32147 reply_id: 128213[/import]

is very strange … had a “main_v2.lua” and a “main.lua” in the same folder and that did not work … I cleaned the folder and now everything works properly :smiley:
Thank you very much for the help. [import]uid: 121547 topic_id: 32147 reply_id: 128218[/import]

mmm, i try with simple “dog.png” and “dog.txt” and not working…

localFile = "dog.png",  
remoteFile = "/dominio.com/upload/dog.png",  

and

localFile = "dog.txt",  
remoteFile = "/dominio.com/upload/dog.txt",  

Help me…
do you have some example? @peach, any help??

Thanks
[import]uid: 121547 topic_id: 32147 reply_id: 128184[/import]

Does the directory:

/domino.com

exist on the ftp server? What about the directory:

/domino.com/upload

??? Does the username userName have write access to the upload directory?

I’ve never used the ftp library before, so forgive my ignorance? What folder does Icon-Small.png or dog.png exist in? Is it in the system.ResourcesDirectory (where your main.lua file is)? Is it in the system.DocumentsDiretory or the system.CachesDirectory? Which folder does the ftp app look at to begin with? For instance if its looking in system.DocumentsDirectory (a logical place for your app to write files too) and you’re Icon-Small.png lives in the Resource Bundle, I don’t see anything above to tell FTP were to find the image at.
EDIT**** I may have answered some of my own questions. It looks like you are trying to use Graham Ransom’s ftp helper from the community code. If thats the case, then this is the syntax to upload a file:

connection:upload{  
 localFile = system.pathForFile("image.jpg", system.ResourcesDirectory),  
 remoteFile = "/public\_html/image.jpg",  
 onSuccess = onUploadSuccess,  
 onError = onError  
)  

Note the line that reads:

system.pathForFile(“image.jpg”, system.ResourcesDirectory),

This is critical as your app runs in a sandbox, this is how you file files and give the app a path to find it. In this case, if your Icon-small.png is in the resource bundle (same folder as main.lua) then you would do:

localFile = system.pathForFile("Icon-small.png", system.ResourcesDirectory),  

If the file dog.png lives outside the resource bundle, say something you created with io.write or something saved by one of the photo saving tools, its like to be in the DocumentsDirectory

localFile = system.pathForFile("dog.png", system.DocumentsDirectory),  

without this system.pathForFile() call you’re not going to find the file to upload.
[import]uid: 19626 topic_id: 32147 reply_id: 128195[/import]

Hi robmiracle,
i try…

“Icon-small.png” (and dog.png) is same folder as main.lua
localFile = system.pathForFile(“Icon-small.png”, system.ResourcesDirectory),

and the new file
gato.txt is in documents…
localFile = system.pathForFile(“gato.txt”, system.DocumentsDirectory),

in corona simulator work ok, but iPhone send the file via FTP to my server with the same name and extension (“gato.txt” or “Icon-small.png”) but have a size of zero k. both throw errors when opened. Besides the message indicating the FTP function is ERROR.

therefore rule out that the problem is with the sending of the file, and I did a test by placing a fictitious name to send and the system upload this file Likewise ghost zero size k. I gather then that the problem is that the app loaded on your iPhone or iPad can not find the ORIGINAL.
[import]uid: 121547 topic_id: 32147 reply_id: 128213[/import]

is very strange … had a “main_v2.lua” and a “main.lua” in the same folder and that did not work … I cleaned the folder and now everything works properly :smiley:
Thank you very much for the help. [import]uid: 121547 topic_id: 32147 reply_id: 128218[/import]