使用JSFtp和Javascript发送文件

Sending file using JSFtp and Javascript

本文关键字:文件 Javascript JSFtp 使用      更新时间:2023-09-26

我想使用JSFTP发送一个文件。首先,我必须创建一个文件夹,我将把文件放在那里。这工作正常,所以连接正常。但当我想上传文件时,我得到了这个:

DEBUG:  user_command
"stor fo994201-836f-48d0-925b-52068b8a49be/20160511/undefined"
DEBUG:  response
{
  "code": 550,
  "text": "550 '' was not found.",
  "isMark": false,
  "isError": true
}
{ [Error: 550 '' was not found.] code: 550 }

我不明白为什么我得到:在stor命令中未定义。。。这是创建文件夹和发送文件的代码部分:

//Create the new folder
Ftp.raw.mkd("fo994201-836f-48d0-925b-52068b8a49be/"+date, function(err, data) {
  if (err) return console.error(err);
  console.log(data);
  console.log("Trying to Upload file.");
  for (var i=1; i<filenames.length; i++){
      console.log (" Sending : " + filenames[i]);
      fs.readFile(path+date+'/'+filenames[i], "binary", function(err, data) {
        var buffer = new Buffer(data, "binary");
        Ftp.put(buffer, 'fo994201-836f-48d0-925b-52068b8a49be/'+date+'/'+filenames[i], function(err) {
              if (err){
              console.log(err);
          } else {
              console.log("File uploaded successfully");
          }
          setTimeout(function(){}, 20000);
        });
      });
  }
});

调试输出:

Trying to Upload file.
 Sending : test.txt
DEBUG:  user_command
"pasv"
DEBUG:  response
{
  "code": 227,
  "text": "227 Entering Passive Mode (54,194,108,219,214,8)",
  "isMark": false,
  "isError": false
}
DEBUG:  user_command
"stor fo994201-836f-48d0-925b-52068b8a49be/20160511/undefined"
DEBUG:  response
{
  "code": 550,
  "text": "550 '' was not found.",
  "isMark": false,
  "isError": true
}
{ [Error: 550 '' was not found.] code: 550 }

简单的解决方案:如果你想使用扩展文件,你需要使用mput,而不是put。所以它正在与mput合作。