Visual Studio Publish Website Using SCP/SFTP

淺唱寂寞╮ 提交于 2021-01-20 16:37:58

问题


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?


回答1:


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.




回答2:


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

Combine ssh and rsync

  • 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/"

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.



来源:https://stackoverflow.com/questions/1549709/visual-studio-publish-website-using-scp-sftp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!