Robert-W / grunt-ftp-push

Deploy files to an FTP server as part of your Grunt workflow.
MIT License
39 stars 14 forks source link

An error message will appear after the FTP connection closed. #19

Closed zzbo closed 9 years ago

zzbo commented 9 years ago

Recently encountered a problem when I using the grunt-ftp-push to upload some files to FTP server. When the files are transferred successfully, an error message "Fatal error: write after end" will appear on the console, my grunt-ftp-push configuration is as follows:

        ftp_push: {
              test: {
                options: {
                    host: 'testhost.com',
                    username : 'testuser',
                    password : 'testpassword',
                    dest: '/testdir/',
                    port: 21
                },
                files: [{
                    expand: true,
                    cwd: '.',
                    src: [
                        '<%= testBranch %>/**',
                        '!<%= testBranch %>/node_modules/**',
                        '!<%= testBranch %>/.svn/**',
                    ]
                }]
            }
        }

and then I try to debug the grunt-ftp-push, I add 'ftpServer.destroy();' after

grunt.log.ok("FTP connection closed!");
done();

in the function 'closeConnection' and restart grunt, this problem does not happen again.

zzbo commented 9 years ago

I using grunt-ftp-push 0.3.2.

Robert-W commented 9 years ago

So it sounds like you may have fixed the error you were seeing by adding ftpServer.destroy() to the closeConnection function. Can you verify that all your flies are uploaded correctly after running this?

Googling this error unfortunately does not turn up much, it seems all posts related to it have to deal with issues in browserify or some unit testing module, so Im not positive about what it is that may cause this issue. Maybe something to do with the ftpServer not finishing up some task before I call done() but pure speculation at this point since I have not seen this before.

If adding ftpServer.destroy() fixes it for you I will leave this ticket open and add to it If I find something. I'll also try to push out a patch some time soon that has the ftpServer.destroy() in it.

zzbo commented 9 years ago

I confirm this case once again, I found grunt-ftp-push require 'jsftp' module, and then I try to find a similar problem in ‘jsftp’ module. I get a issue https://github.com/sergi/jsftp/issues/71

Robert-W commented 9 years ago

Ill see if I can take a look this weekend, Is it at least completing the file transfers or is this happening mid transfer?

zzbo commented 9 years ago

It happens when the transfer is complete.

Robert-W commented 9 years ago

Ok thanks, Ill see what I can come up with this weekend.

In the meantime, if you have a chance to run this again, can you try setting debug to true in your options and pasting the last bit of statements it prints out.


options: {
  host: 'testhost.com',
  username : 'testuser',
  password : 'testpassword',
  dest: '/testdir/',
  port: 21,
  debug: true
},
files: [
  { ... }
]

This debug setting runs jsftp in debug mode and will output a ton of stuff to the console and there may be some helpful information around where it fails.

Just a note, don't post the whole contents, the first few debugging statements may contain your host and credential information, just post the section around where it fails.

zzbo commented 9 years ago

qq 20150123144005 I've added 'debug: true' to the configuration as you say, but the error message does not change.

Robert-W commented 9 years ago

Hmm crap, I was hoping to see something like at the end of this comment below. Anyway thanks for trying, Ill try to dig into this tomorrow and Sunday and see what I can come up with. I read on that post that you linked that someone had some success using ftpServer.destroy(); instead of ftpServer.raw.quit(); so maybe I can clean up the closeConnection function a little and see if that helps.


>> /www/wp-content/themes/test/_footer_newsletter.php transferred successfully.
DEBUG:  user_command
"pasv"
DEBUG:  response
{
  "code": 226,
  "text": "226-File successfully transferred\n226 0.340 seconds (measured here), 2.62 Kbytes per second",
  "isMark": false,
  "isError": false
}
DEBUG:  response
{
  "code": 227,
  "text": "227 Entering Passive Mode (213,186,33,201,200,11)",
  "isMark": false,
  "isError": false
}
DEBUG:  user_command
"stor /www/wp-content/themes/test/_footer_team.php"
DEBUG:  response
{
  "code": 150,
  "text": "150 Accepted data connection",
  "isMark": true,
  "isError": false
}
>> /www/wp-content/themes/test/_footer_team.php transferred successfully.
Robert-W commented 9 years ago

One thing you can possibly try in the meantime is the closeConnection function.

Try changing this:


function closeConnection(errMsg) {
    if (ftpServer) {
      ftpServer.raw.quit(function(err, res) {
        if (err) {
          grunt.log.error(err);
          done(false);
        }
        grunt.log.ok("FTP connection closed!");
        ftpServer.destroy();
        done();
      });
    } else if (errMsg) {
      grunt.log.warn(errMsg);
      done(false);
    } else {
      done();
    }
  }

to:


function closeConnection(errMsg) {
    if (ftpServer) {
      ftpServer.destroy();
      grunt.log.ok("FTP connection closed!");
      done();
    } else if (errMsg) {
      grunt.log.warn(errMsg);
      done(false);
    } else {
      done();
    }
  }

This is probably going to be the first thing I would attempt anyway.

Robert-W commented 9 years ago

Closing this issue as inactive for some time. If issue shows up again we I can reopen this.