I'm trying to create what I thought would be a simple .bat file to login to a Unix server and cd/dir but I can't seem to get it to do anything past the initial login. What I've tried so far:
#echo off
putty -load "servername" -l username -pw pass
echo cd /usr/frank/ftp/bin
Also tried creating a separate file to be called for the chdir but it's not calling the other file either.
-m C:\Users\Userzed\Desktop\ftp.txt
echo cd /usr/frank/ftp/bin
I appreciate any help to show me why this isn't working or point me to where I'm messing this up.
Related
I had to automate my postgre database backup. As instructed by my software vendor I am trying to use pg_dump.exe (see below) file to take a backup but that prompts me for password.
.\pg_dump.exe -h localhost -p 4432 -U postgres -v -b -F t -f "C:\Backup\Backup.tar" Repo
So googled and found that as per "https://www.postgresql.org/docs/9.6/libpq-pgpass.html" I can create a pgpass.conf file within 'C:\Users\User1\AppData\Roaming\postgresql\pgpass.conf" which I did.
Then I tried to pass data of pgpass.conf file to env variable before executing my pg_dump command. But it is not working. Still I am getting prompt to enter password. This is the content of pgpass.conf file: *:*:*:postgres:password
Below is the code I am trying in PowerShell,
$Env:PGPASSFILE="C:\Users\User1\AppData\Roaming\postgresql\pgpass.conf"
cd "C:\Program Files\Qlik\Sense\Repository\PostgreSQL\9.6\bin"
.\pg_dump.exe -h localhost -p 4432 -U postgres -v -b -F t -f "C:\Backup\Backup.tar" Repo
Why am I still being asked for password?
When I type following code $Env:AppData I get following response "C:\Users\User1\AppData\Roaming"
Everywhere there are guidance on how to use it in UNIX or command prompt but not in powershell. Any help is appreciated. Also if you could direct me how to secure this password file then it will be great.
With password prompt I cannot automate it with windows task scheduler.
I suspect you have a suitable solution, however, as a quick (and not secure) workaround via the command prompt, you can use the variable PGPASSWORD to hold the password then run the backup script.
A sample might be something like:
SET PGPASSWORD=password
cd "C:\Program Files\Qlik\Sense\Repository\PostgreSQL\9.6\bin" pg_dump.exe -h localhost -p 4432 -U postgres -b -F t -f "d:\qs_backup\QSR_backup.tar" QSR
Rod
I have yet to get the damned thing to work yet, but I did find this:
-w
--no-password Never issue a password prompt. If the server requires password authentication and a password is not available by other means
such as a .pgpass file, the connection attempt will fail. This option
can be useful in batch jobs and scripts where no user is present to
enter a password.
I don't see a -w parameter in your call to pg_dump
I used pg_hba file to allow connection "trust" this is riskier method but I had to get things done ASAP. Thank you for your time and effort
Ive been using a .bat script to download only pdfs from an FTP server.
Up until now its been working perfectly using the mget *pdf function.
I recently moved the script and have it running from a Windows 2012 Server.
And now when script gets to the mget function, it lists the files that would normally transfer except with a ? after each instance, it then fails to actually download them to the lcd.
#ftp -v -n -i -s:C:\Users\LMCT\Desktop\Serversidesage\download-1.txt
This is the FTP function being called.
open xx.xxx.xx.xxx
user xxxxxxxxxxx
=xxxxxxxxxxxx
cd orders
lcd "C:\Users\LMCT\Desktop\Magento-downloaded-orders"
binary
prompt
mget *pdf
mdelete *pdf
quit
And this is the downloading script.
Does anyone know why this might be happening?
Thanks in advance.
Kind Regards, Lewis.
By Default Interactive Prompting is ON. When you used the -I option to launch the FTP command it is turning Prompting off. In your script you are then turning it back on with the PROMPT command which then throws off your MGET command.
So if the PROMPT command is in your FTP script:
open ftp.domain.com
user ftpuser
password
prompt
quit
It is easy test to see what is going on.
C:\BatchFiles\ftp>ftp -v -i -n -s:"script.txt" |find "Interactive"
Interactive mode On .
C:\BatchFiles\ftp>ftp -v -n -s:"script.txt" |find "Interactive"
Interactive mode Off .
I am trying to write a script to automatically upload files to a sftp server. My problem is authentication.
I know it is not possible to store a password in a bash script for sftp.
I can't use keys because the admin of the server won't allow me.
I don't want to use any extras (sshpass/expect) because I can't
guarantee they will be on the machine I'm using (the script are wanted so that the processes are not tied down to a particular machine).
Manual entry of the password is not a problem I just need to get the script to wait for the user to put the password in. At the minute when I run the script it opens terminal, prompts for the password, but when this is entered nothing else happens. If I enter the lines of code manual after it uploads everything correctly.
#!bin/bash/
cd /remote_directory
lcd /local_directory
put some_file.txt
After months of looking for an answer I have finally found the solution. It was in a comment on an answer in some other thread I can't even remember. Hope this can help others out there.
Your bash script should look like this and will connect to the sftp server, prompt the user for the password, and then execute the remaining commands.
#!/bin/bash
sftp user#server <<!
cd /the/remote/directory
lcd /your/local/directory
put/get some.file
!
I'm trying to run a .bat file from windows xp using putty sftp. My code is below. For some reason, I keep getting an "access denied".
The annoying thing is that when I copy>paste these into the cmd prompt line by line, it works fine! I'm not sure if there's still some error with my code or if it's possible that the ftpsite.com won't accept incoming messages from a batch file?
#echo off
psftp user#ftp.ftpsite.com -pw abc#!123
cd Data/out
get file.csv
Commands to PSFTP must be placed in a SCRIPT file as in:
Filename: myscript.scr
cd Data/out
get file.csv
exit
Then you call it with:
#echo off
psftp user#ftp.ftpsite.com -pw abc#!123 -b myscript.scr
In my script - i create a sftp connection.
I read some directory value from user earlier and once the sftp connection is established, i try to cd to that dir which i got from the user.
But its not working, probably bec the prompt goes inside the server to which the SFTP connection was established.
In this case how to make it work ?
I also faced this problem and was able to find the solution. The solution is right there in the man page of sftp. In the man page, you will find where it is written the format of using sftp like this:
sftp [options] [user#]host[:dir[/]]
Actually, two formats are given there but this is the one I wanted to use and it worked.
So, what do you do? You simply supply the username#host as seen there, then, without any space followed by : and the path you want to change to in the client/remote server in your script and that's all. Here is a practical example:
sftp user#host:/path/
If your script does, as you state somewhere in this page,
sftp $user#$host cd $directory
and then tries to do something else, like:
sftp $user#$host FOO
That command FOO will not be executed in the same directory $directory since you're executing a new command, which will create a new connection to the SFTP server.
What you can do is use the "batchfile" option of sftp, i.e. construct a file which contains all the commands you'd like sftp to do over one connection, for example:
$ cat commands.txt
cd foo/bar
put foo.tgz
lcd /tmp/
get foo.tgz
Then, you will be able to tell sftp to execute those commands in one connection, by executing:
sftp -b commands.txt $user#$host
So, I propose your solution to be:
With user's input, create a temporary text file which contains all the commands to be executed over one SFTP connection, then
Execute sftp using that temporary text file as "batch file"
Your script would do something like:
echo "Directory in which to go:"
read directory
temp=$( mktemp /tmp/FOOXXX )
echo "" > $temp
echo "cd $directory" >> $temp
# other commands
sftp -b $temp $user#$host
rm $temp
If you are trying to change the directory of the machine, try lcd
In what way is it not working? To change directories on the remote server, you use the "cd" command. To change directories on the local server, you use the "lcd" command. Read "man sftp".