User input path psftp script batch file - command-line

I am trying to implement a scenerio like the user should give a path and the path should be binded to another .
bat file and that path should be the destination where am going to put my file from local.
My code looks like this:
Getfile.bat:
set /P INPUT=Type input:
psftp <user>#<IP> -b D:\FileTransfer.bat -pw <PW>
Filetransfer.bat:
cd %INPUT%
lcd d:\
put log.sh
Error :Access denied Remote working directory is /home/irisuser Directory /home/irisuser/%INPUT%: no such file or directory

Your variable %INPUT% is not passed to Filetransfer.bat. If you want psftp to cd into a user-defined directory, you have to create Filetransfer.bat on the fly:
set /P INPUT=Type input:
>D:\Filetransfer.bat echo.cd %INPUT%
>>D:\Filetransfer.bat echo.lcd d:\
>>D:\Filetransfer.bat echo.put log.sh
psftp <user>#<IP> -b D:\FileTransfer.bat -pw <PW>

Related

Copy and unzip files from windows to remote linux machine - powershel script

I have a ./build folder (inside a project on a Windows machine) that I need to compress and send to a remote Linux server where I need to unzip it.
Here's the cmdlet function that I wrote (it doesn't work as intended):
function scpFileFromBuildFolder {
param (
[string]$userAndHost,
[string]$targetDirectory,
)
Compress-Archive -Force -Path "./build/" -Destinationpath "./build/main.zip" -CompressionLevel Optimal
Write-Host -fore Cyan "`r`nCopying archive from ./build/ to ${targetDirectory}"
. scp "./build/main.zip" "${userAndHost}:${targetDirectory}"
Write-Host -fore Cyan "`r`nDecompressing archive on a remote directory:"
. ssh $userAndHost ". cd ${targetDirectory}"
. ssh $userAndHost ". unzip main"
. ssh $userAndHost ". cd build/"
. ssh $userAndHost ". find . -maxdepth 1 -exec mv {} .. \" # move all files to a parent dir
. ssh $userAndHost ". cd .."
. ssh $userAndHost ". rm -rf build build.zip main"
. ssh $userAndHost ". exit"
}
As you can see, I tried to perform multiple commands on a remote server via ssh. All of that works if I do things manually through PowerShell: I compress the file, scp it, and ssh to the server where I unzip the file and do all the other things. But it doesn't work this way through a .ps1 script — it only copies the file but doesn't do anything after the print statement ("Decompressing archive on a remote directory:").
Please, help me finish this function.
You should only run ssh once, with any remote commands getting fed to ssh up through to exit. Otherwise it will just pause and wait for more commands. For example:
ssh $UserAndHost "cd /tmp; hostname; pwd; exit"
You can put them on separate lines like a bash script, BUT be careful of crlf line endings (or strip them):
Write-Host -fore Cyan "`r`nDecompressing archive on a remote directory:"
ssh $userAndHost "cd ${targetDirectory}
unzip main
cd build/
find . -maxdepth 1 -exec mv {} .. \ # move all files to a parent dir
cd ..
rm -rf build build.zip main
exit"
# ERROR if crlf like:
bash: line 1: $'\r': command not found

How to pass find command out to scp command to copy all directories from the remote server to local directory

I tried to use this command line in Windows:
My goal is to find all the directories in root#xx.xx.xx.xx:/var/log/ for a specific port and download them locally.
For the find command, I am excluding all folders which include this name "logFolder".
set outputPath=C:\MyDestination
scp -P 22 -r 'find root#xx.xx.xx.xx:/var/log/ -type d \( ! -name logFolder \)` %outputPath%

No such file or directory cygwin + rsyc

I am trying to send a file in cygwin commandline with rsync and openssh.
So the command I'm using is rsync -P -e "ssh -p 2222" deborahtrez#209.6.204.90:/home/dell/cygdrive/c/Users/dell/Videos/Movavi/installation_tutorial.mp4
Then it asks for my password, which I enter. I press ENTER and I always get returned No such file or directory
The file path to my video "installation_tutorial.mp4" is in C:\Users\dell\Videos\Movavi so the full path becomes C:\Users\dell\Videos\Movavi\installation_tutorial.mp4. So this is what I have tried so far.
Please, what am I doing wrong? Is it my file path? If so, what is the correct file path that i should be using? Help!
The path is wrong. The best way to convert from Windows to Posix is to use cygpath
$ cygpath -u 'C:\Users\dell\Videos\Movavi\installation_tutorial.mp4'
/cygdrive/c/Users/dell/Videos/Movavi/installation_tutorial.mp4

Using psexec to copy files from local machine to a remote desktop

Inorder to copy files from my local system to a remote desktop I use the following command
psexec \\192.168.xx.xx -u username -p password xcopy "C:\Users\User\Desktop\source" "\\192.168.xx.xx\C$\Users\User\Desktop\target" /S /Y /F /I
I am getting a this error
0 File(s) copied
`ƒ♦╝# zü┴k
xcopy exited on 192.168.xx.xx with error code 4.

How to ZIP specific files from a folder using Winzip command line?

With this command, I'm able to ZIP all files from the folders:
wzzip.exe -a -p -r C:\DestinationPath\DataFiles_20130903.zip C:\SourcePath\*.*
But, my folder has .dat,.bat,.txt,.xls files.I want to ZIP only .dat and .bat file.How to do this?
Thanks.
use this command (for the particular scenario in the question):
wzzip.exe -a -p -r C:\DestinationPath\DataFiles_20130903.zip C:\SourcePath\*.dat C:\SourcePath\*.bat
for more command line options for winZip refer to the following links:
winZip command line Reference 1
winZip command line Reference 2
To provide multiple file names you can also use #filename where the filename is a file which contains the list of files which you want to include in the zip file.
If you are making the command configurable then you can ask the user/ other program which is calling your command to select the file extensions and then write these selected extensions into the "filename" file using java code or any other language you prefer.
For example if the user selects bat and dat , then write "C:\SourcePath\*.bat" and "C:\SourcePath\*.dat" into the file(assume filename is fileExtensions.txt) and call the command
wzzip.exe -a -p -r "C:\DestinationPath\DataFiles_20130903.zip" #"C:\SourcePath\fileExtensions.txt"
You can use the D7zip
An excellent zipador file and folders D7zip.exe
link to download
https://drive.google.com/file/d/0B4bu9X3c-WZqdlVlZFV4Wl9QWDA/edit?usp=sharing
How to use
compressing files
D7Zip.exe -z "c:\fileout.zip" -f "C:\filein.txt"
compressing files and putting password
D7Zip.exe -z "c:\fileout.zip" -f "C:\filein.txt" -s "123"
compressing folders
D7Zip.exe -z "c:\folderout.zip" -f "C:\folderin\"
unzipping files
D7Zip.exe -u "c:\fileout.zip" -f "c:\folderout\"
unzipping files that have password
D7Zip.exe -u "c:\fileout.zip" -f "c:\folderout\" -s "123"
decompressing files by extension
D7Zip.exe -u "c:\fileout.zip" -f "c:\folderout\*.txt"
decompressing files without asking for confirmation to replace
D7Zip.exe -u "c:\fileout.zip" -f "c:\folderout\" -r
help
D7Zip.exe -?
D7Zip.exe by Delmar Grande.
If the command line given above is right then give this a go: but check the paths.
#echo off
pushd "C:\SourcePath"
"c:\program files\winzip\wzzip.exe" -a -p -r "C:\DestinationPath\DataFiles_20130903.zip" *.dat *.bat
popd