SFTP - WinSCP: Zip a file/folder - zip

I'm transferring a file to SFTP and then trying to zip it with WinSCP. It's not working.
After my put command, I'm using the following command.
zip -r "!?&SFTP Folder Path\MyFile.txt:?SFTP Folder Path\MyFile.zip!" !&
What am I doing wrong? What should I be doing? If I only want to zip a/any file with specific extension or folder, what changes do I make?
Update:
I'm getting the following log output after a file has been copied over to the sftp
...
batch continue Searching for host...
Connecting to host...
Authenticating...
Using username "admin". Authenticating with pre-entered password. Authenticated. Starting the session...
I'm using the following code after put cmd line.
option batch continue
call zip -r "/sftp folder/Myfile.zip" Myfile.csv
close
exit

Your syntax is a custom command. The custom commands is a GUI feature of WinSCP, it has nothing to do with the scripting.
In WinSCP scripting use the call command.
call zip -r /path/MyFile.zip file1.dat file2.dat ...
Though make sure you are allowed to execute shell commands on the server.

Related

Execute mirror and mget lftp commands in bash script

Current code
#!/bin/bash
SFTP_SERVER="sftp.url.com:/csv/test/10"
SFTP_USER="user"
SFTP_PWD="pwd"
## not sure if this line is needed given I specify the local directory
# in the next block of code.
cd /mnt/c/Users/user/Documents/new_directory
lftp sftp://$SFTP_USER:$SFTP_PWD#$SFTP_SERVER
lftp -e mget *.csv mirror sftp.user.com:/csv/test/10 /mnt/c/Users/user/Documents/new_directory
Objective
Download all csv files and mirror my local directory folder with the remote server, so when the code is run again it won't download a second file.
Error received
open: *.csv: Name or service not known
Comments
From what I understood of the lftp man page I should be able to get all wildcard files by using mget instead of the standard get, provided I use -e to use external commands. I've run mget manually and can download the files without issue but it doesn't seem to support the *.csv in the script.
Appreciate any feedback you can provide as to why my code won't download the files and what I might have misunderstood from the man pages.
It should be like:
lftp sftp://$SFTP_USER:$SFTP_PWD#$SFTP_SERVER -e "mget *.csv; bye"

SVN TortoiseProc.exe : command to export the result displayed in Showcompare:

I am trying to automate our deployment process.
Question :- Am using this command to get modified files between trunk and working folder.
TortoiseProc.exe /command:showcompare /url1:C:\SVN\branches\Working_folder/folder1 /revision1:HEAD /url2:C:\SVN\trunk\folder1 /revision2:HEAD
With this command i get some midified file.
Now i want to export this list of files to my local C:\temp by using some command.
Please let me know if you need any other information.
TortoiseProc is User Interface tool; it doesn't print anything to stdout, so you cannot use this data.
Your only option is to use plain svn diff command with url to repositories and redirect your output to the file:
svn diff --summarize http://svn/branches/path_to_working_folder#HEAD http://svn/trunk/path_to_working_folder#HEAD > C:\temp\diff_results.txt
More about this command in here: http://svn.gnu.org.ua/svnbook/svn.ref.svn.c.diff.html

Simple shell/bash based sftp script to upload a file to root directory of destination server

I need to upload a file from source unix server to destination unix server (supports sftp). i'm using simple script below:-
cd /usr/bin
sftp userid#destination_server <<EOF
put myfile /
EOF
I get host key verification failed, Couldn't read packet: Connection reset by peer
I know this must have got something to do with correct public ssh key of my source being not set under destination server. But otherwise , is my script correct. Or do you suggest any other script based on my simple requirement stated above. Please note this doesn't need any password, just user name is sufficient and remote directory is just the root directory, hence using /.
Simply use a SFTP batch file:
sftp -b batchfile.sftp userid#destination_server
with batchfile.sftp containing exactly one line (or whatever more commands you should need)
put myfile /

copy/move files on remote server linux

I log into server_a and run .sh file, which has the following script:
scp user#server_b:/my_folder/my_file.xml user#server_b:/my_new_folder/
to copy files from my_folder to my_new_folder at server_b. It doesn't throw an error, but no files are copied.
Notes:
server_b is accessed by the pre-set rsa_keys.
server_a: unix
server_b: ubuntu
can SCP files from/to these servers without any issues
The end goal is to move or copy/remove files.
There are two possibilities:
Connect from server_a to server_b and do local copy:
ssh user#server_b "cp /my_folder/my_file.xml /my_new_folder/"
Do copy over the server_a. Your method would require the server_b to be able to authenticate to itself, which is probably not the case:
scp -3 user#server_b:/my_folder/my_file.xml user#server_b:/my_new_folder/
Also note that your code copies only one file and not files as you write in the title.
If you are logged on to the server, why are you authenticating again:
scp user#server_b:/my_folder/my_file.xml user#server_b:/my_new_folder/
You should be in the directory of file or simply use scp and use -v parameter to see the debug information.
Run as follows:
scp -v /my_folder/my_file.xml user#server_b:/my_new_folder/
It is not a directory nor it is recursive, so you do not need to -r parameter.

Linux file transfer between server automatically when a file is created

In my work, I use 2 Linux servers.
The first one is used for web-crawling and create it as a text file.
The other one is used for analyzing the text file from the web crawler.
So the issue is that when a text file is created on web-crawling server,
it needs to be transferred automatically on the analysis server.
I've used shell programming guides referring some tips,
and set up the crawling server to be able to execute the scp command without requiring the password (By using ssh-keygen command, Add ssh-key on authorized_keys file located in /root/.ssh directory)
But I cannot figure out how to programmatically transfer the file when it is created.
My job position is just data analyze (Not programming)
So, the lack of background programming knowledge is my big concern
If there is a way to trigger the scp to copy the file when it is created, please let me know.
You could use inotifywait to monitor the directory and run a command every time a file is created in the directory. In this case, you would fire off the scp command. IF you have it set up to not prompt for the password, you should be all set.
inotifywait -mrq -e CREATE --format %w%f /path/to/dir | while read FILE; do scp "$FILE"analysis_server:/path/on/anaylsis/server/; done
You can find out more about inotifywait at http://techarena51.com/index.php/inotify-tools-example/

Resources