gtg092x / gulp-sftp

Gulp SFTP Deploy
140 stars 61 forks source link

gulp-sftp trying to upload directories #34

Closed saschabratton closed 7 years ago

saschabratton commented 9 years ago

I am using gulp-sftp to deploy website changes. It functions as a post-merge git hook.

So, changes to the website are committed and pushed to our git repo. Then for deployment, a server runs git pull to grab all the changes and then they are run thru gulp.

It's pretty simple right now: the changed files are separated with gulp-changed and moved to a "build" directory and then uploaded with gulp-sftp.

My deployment task looks like this:

gulp.task('deploy', function() {
    return gulp.src(src)
    .pipe(changed(dest))
    .pipe(gulp.dest(dest))
    .pipe(sftp({
      host: 'ftp.example.com',
      user: 'username',
      pass: 'password',
      remotePath: '/htdocs/'
    }));
});

This works just fine; however, the gulp deployment task is throwing a lot of errors because it is apparently trying to create the directories that the changed files are in. It can become a bit confusing to parse out the real output to confirm that changes were deployed properly, because of all the noise from directory errors, especially with deeply nested directories.

Here is an example of the output I am seeing:

[11:53:19] Using gulpfile /foo/bar/gulpfile.js
[11:53:19] Starting 'deploy'...
[11:53:20] Authenticating with password.
[11:53:21] SFTP error or directory exists: Error: File already exists. /htdocs/Foo
[11:53:21] SFTP error or directory exists: Error: File already exists. /htdocs/Foo/Bar
[11:53:22] gulp-sftp: Uploaded: Foo/Bar/example.html => Foo/Bar/example.html
[11:54:11] gulp-sftp: 1 file uploaded successfully
[11:54:11] SFTP :: SFTP session closed
[11:54:11] Finished 'deploy' after 52 s
[11:54:11] Connection :: end
[11:54:11] Connection :: close with error

Is there an option or configuration that I have overlooked? Or is this problem related to the way I am using gulp-changed and I should be talking to that group?

pdeschen commented 9 years ago

Looking at the code, expected behaviour.

That being said, I think the code could be enhanced to keep a list of dir already created as we loop, check this list on error and only report error for true ftp error. There's certainly more efficient ways to do it (prune upfront) but that would require more work.

Saturate commented 8 years ago

This has annoyed me as well, not sure on how to fix it. If someone has a suggestion I could do a PR.

toby1kenobi commented 8 years ago

Although the "Known Issues" suggest that for Windows this should be fixed in 0.1.3, I'm still getting this (on Windows) in 0.1.5

saschabratton commented 8 years ago

@toby1kenobi I believe the issue you are referring to is: https://github.com/gtg092x/gulp-sftp/issues/16

I believe that issue is resolved, and while the error message thrown for that issue came from the same call site as this issue, they are not the same issue.

saschabratton commented 8 years ago

Proposed solution: https://github.com/gtg092x/gulp-sftp/pull/61

Looks like there's a couple PR aimed at this issue, but attempting to actually check whether a directory exists or not. Not sure if they are good solutions or not.

My proposed solution simply suppresses the error for existing directories. So there is some overhead because the mkdir commands are still sent.

This solution works for my purposes.

saschabratton commented 7 years ago

Looks like this was fixed in #39 using an undocumented exists() method on the SFTPStream.

Nice find, @hussion!