Visual Studio Publish Website Using SCP/SFTP
Asked Answered
A

2

17

Is there a way to publish a web site from Visual Studio 2008 using SCP or SFTP? I know it is possible to publish to my local filesystem and then perform the transfer with SCP, but I'd like something more seamless (e.g. part of Visual Studio). Does this feature exist? An addin perhaps?

Apostolate answered 11/10, 2009 at 2:53 Comment(0)
B
39

The built in system for publishing pages is a little bit limited.

One thing that I find useful is with WinSCP, there is a featured called "Keep Remote Directory up to Date". What it will do is set a bunch of file system watchers for your local system and if you change something locally, it will auto upload it. Using that and publishing to a local directory makes things easy.

Bromberg answered 11/10, 2009 at 3:20 Comment(2)
Slick feature, never knew it existed until now. Too bad Filezilla doesn't offer anything like this.Coprology
too bad it only supports putty shh filesUnscrew
C
7

If you have Windows 10 and bash/linux subsystem installed and a Linux/BSD server you can:

Combine ssh and rsync

I prefer to use rsync through a ssh pipe, since it won't upload files that werer not modified, it's more efficient.

  • from visual studio, publish in a folder, say I:/www/WebProject
  • use this command that updates changes only, and delete files that were deleted/absent from publish folder thanks to --delete

bash -c "rsync -avH --delete --progress /mnt/i/www/WebProject -e ssh server:/var/www/"

Where I:/www/WebProject is the local folder where the project was published, and /var/www the remote directory of the web application.

Preparation (to do once)

You need to work a bit to allow ssh to work without password but with keys.

  • let's say your bash username is also the same on the server; if not, just use username@server

  • name your server:

  • add xx.xx.xx.xx server to the file c:/windows/system32/drivers/etc/hosts)

  • add your server to hosts from bash with sudo echo "xx.xx.xx.xx server" >> /etc/hosts

  • from bash, generate your keys:

ssh --keygen then [enter] (no passphrase)

  • send your public key to the server, in your home folder:

scp ~/.ssh/id_rsa.pub servername:~/

  • from your server (ssh server then password):

cat id_rsa.pub >> .ssh/authorized_keys && rm id_rsa.pub

Now you can ssh and scp without password. IMO this is way better than filezilla or just scp.

Cottonweed answered 6/12, 2017 at 13:12 Comment(3)
I don`t quite understand what is going on here, can you please elaborate more on each step. Though it is clear to me your answer is correct and interesting. what commands to run in the windows powershell, what commands is to run in the windows WSL, what commands to run in the remote Linux serverOften
@RaidenCore It's not exactly an answer for beginners, but it's not mysterious too. Only when I used a command starting with bash, it's from powershell, the rest is from local bash (wsl), and when it's not local (from server), I mentionned it.Cottonweed
I figured it out, thanks.Often

© 2022 - 2024 — McMap. All rights reserved.