On Nov 14, 2014, at 1:23 AM, Brendan Thompson wrote:

> Hello. I'm developing an extension for Adobe CC products (CEP) that uses node 
> to upload a small CSV file to an ftp server. 
> 
> Using jsftp I'm able to write a file to my server but the contents are empty. 
> Its just and empty file and not the data I intended to send.
> 
> Here is my code.
> 
> function uploadHours() {
>     var jsftp = require("jsftp");
> 
> var ftp = new jsftp({
>   host: localStorage.host,
>   port: Number(localStorage.port), // defaults to 21
>   user: localStorage.user, // defaults to "anonymous"
>   pass: localStorage.ftpPass // defaults to "@anonymous"
> });
> 
> ftp.auth(localStorage.user, localStorage.ftpPass, function(hadErr) {
>     if (!hadErr)
>     alert("auth succesfull")
> });
>     ;
>   ftp.put('C:/Program Files/Adobe/Adobe After Effects CC 2014/Support 
> Files/Hours Tracker/index2.html', '/public_html/indexTester2.html', 
> function(hadErr) {
>       if (!hadError)
>     alert("File transferred successfully!");
>   });
> }
> 
> I'm what you call a total rookie at node so any help is awesome.

Is this code running in a browser or in node? If it's running in a browser, 
then I don't see how it can work, because you're accessing filesystem paths 
("C:/Program Files/...") which you won't have permission to do. And if it's 
running in node, then I don't see how it can work, because you're accessing the 
nonexistent alert function and localStorage object; try using console.log 
instead of alert, and using normal variables instead of localStorage.

Either way, there are a lot of things in this code that look wrong.

I'm not familiar with jsftp, but I'm confused by the fact that you're passing 
the username and password in the options object when calling the jsftp 
constructor, but then are passing the same username and password to the 
ftp.auth function. Seems odd that you would have to provide the credentials 
twice. Are you sure that's how jsftp is meant to be used?

Your code doesn't look very asynchronous to me. You're calling ftp.auth, and 
not waiting for the result of that operation before calling ftp.put. Possibly 
the server hasn't authenticated you yet by the time you've started the put. For 
starters, try putting the ftp.put invocation inside the callback in the 
ftp.auth invocation, after you've ensured no error occurs. You also need a way 
of informing whatever code called uploadHours() when it is complete, and if an 
error occurred. Usually this is done by using a callback, i.e. you would define 
your function as "function uploadHours(callback)" and it would call 
"callback()" when it's done, or "callback(err)" if an error occurred (assuming 
"err" is an error object describing the error).

Note also that you have a typo in your error handling. In your ftp.put 
invocation you've named the parameter "hadErr" but are then accessing the 
undefined variable "hadError". Looks like the jsftp project's documentation 
uses these two different variable names in different examples, which is 
confusing. You might send them a pull request to always use the same error 
variable name for consistency.



-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/DB969F31-F942-4B04-956F-F91259B64E83%40ryandesign.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to