Hi, everyone, I am trying to write a script to login automatically using username and password to an sftp server (the key authentication has been disabled so I cannot use that method).
I tried to search online for a solution and found a way using “expect” but my boss does not want me to use expect since the passwords need to be provided in plain-text.
I am a newbie about this sftp server. Please help out, thanks alot 🙂
Hi
Its the part of requirement that I need your help, though in real scenario its rather complex
My Requirement is ..
I need to transfer files from server 1 to server 2.
Server 1
source directory is say /home/abc/test
it has 2 files in pattern
xxx_data_20130417.dat
xxx_data_20130417.txt
the content of xxx_data_20130417_002.txt is like this
COL1=HELLO
COL2=
also there is one more file val.txt in server1
$cat val.txt
001
Now I want to move the above 2 files to server 2 ( dir: /xyz/src/).
If sftp succeeded it will read the value from file val.txt ( path /home/abc/test
in server 1) increment it and rename the two files something like
xxx_data_20130417_002.dat
xxx_data_20130417_002.txt
and also
update the xxx_data_20130417_002.txt like this
COL1=HELLO
COL2=002
update the val.txt like this
002–previously it was 001
after this it will remove the two files from server1.
If sftp failed then files wont be deleted from server 1 and also the value of val.txt file wont be changed.ie, it will remain 001
I tried using
scp xxx_* usr@septen:/xyz/src/ and can transfer files.
Hi,
I’m facing the following strange issue with SFTP execution. I need to copy a file ‘abc.txt’ from Remote m/c(MyServer) to local machine(Server1). I’ve this file in the folder /users/XYZ on MyServer and need to SFTP it to /users/ABCD on Server1.
On Server1:
————————-
cd /users/XYZ
> ls TEST
>TEST/ /* TEST is a sub dir in /users/XYZ */
>ls abc.txt
> /* ls returns no thing as the file doesnot exists here and I need to get it to a folder TEST under this dir */
>sftp uname/pwd@MyServer
> ls /users/ABCD/abc.txt
abc.txt /* File exists*/
> get /users/ABCD/abc.txt /users/XYZ/TEST/abc.txt
sys err:
>bye
On Server1:
——-
>ls /users/XYZ/TEST/abc.txt
>/* returns no file with such a name
>ls /users/XYZ/abc.txt
>abc.txt /*File got copied here as I exected SFTP command from here*/
When I execute this, my intention was to get the file ‘abc.txt’ on to ‘/users/XYZ/TEST‘, but the execution seems to be a fail, but the catch is that the file gets copied to /users/XYZ, but not to my intended location.
When I’m in /users/XYZ/TEST and When I give “get /users/ABCD/abc.txt” through SFTP without local path details with out any error, the file gets placed in /users/XYZ/TEST.
My requirement is that I should execute SFTP from /users/XYZ dir and get the file on to /users/XYZ/TEST folder with out the sys error.
I have a program running on unix that creates a text file as part of a triggered event. the text files are written to the same directory everytime. There are 15+ users that could possibly be creating the files.
Once the file is created, I need to move the file to a third party system.
the only control/access for this system i have is a username, password and IP address. This server can be accessed by SFTP. I can SFTP the server and provide the password, and execute whatever commands are needed.
question 1 : the user name given to me by the third party is 15 characters long.
and as far as i can see, unix will only allow 8 characters.
when generating the keys (ssh-keygen) on our side, do the names have to match.
question 2: there seems to be a lot of different opinions on what the file permissions for the .ssa directories and files should be on both the host and client. any information in this area would be useful
I am in the process of replacing SFTP instead of FTP to make data more secure. In one of my FTP script I have Quote Site command. I would like to know, what is the option to replace this in SFTP
Code:
ftp -n -v </dev/null
open $remote_address
user ${remote_login_id} ${remote_password}
quote site $quote_site_cmd
cd $remote_dir
binary
put $local_file $remote_file
quit
I have an HP-UX server that runs a script each night. The script connects to an SFTP server and downloads all xml files (if any are present) from a certain folder, and then deletes the files from the SFTP server. So sometimes it will download a new file, sometimes it will download 2 or 3 new files, and sometimes it will download zero new files.
The files are all downloaded to a folder on my server that contains dozens of other similar files.
If/when a new file gets downloaded, I need to run other scripts against it, to processes the data. I’m doing it manually right now. Does anyone know of a better way to identify 1. Whether or not any new files are present. 2. What the file name is of the new files.
My thought is to capture the output of “ls”, then run the sftp download script, then capture the output of “ls” again, and run a diff on the two. That seems a little clunky though, there must be a cleaner way.
When i run a script in linux. It shows the following error.
‘icsftpagent.sh: line 114: syntax error near unexpected token `’icsftpagent.sh: line 114: `Nicsftp() The script is as follows.
#!/bin/bash
#### Copyright Notice:
####
#### Copyright (c) 2007 Network Intelligence Corporation
####
#### Warning: This computer program is protected by copyright law and
#### international treaties. Unauthorized reproduction or distribution
#### of this program, or any portion of it, may result in severe civil
#### and criminal penalties, and will be prosecuted to the maximum
#### extent possible under the law.
####
#### RSA, The Security Division of EMC – Automated FTP/SCP/SFTP Script v2.7.11
####
###################
####
#### Begin User configuration
####
##########
########
######
####
#SILENT MODE
#produce no output to the console;
#set this to true when running from cron
#to reduce emails sent to root. SILENT=true
# Have the Solaris POSIX compliant binaries first in the path.
# The /usr/bin directory in Solaris doesn’t have POSIX compliant
# binaries. This is particularly a problem for the awk command we are
# using. (ECE-138)
#PATH=/usr/xpg6/bin:/usr/xpg4/bin:/usr/css/bin:$PATH
## Enter the hostname/IP address of the enVision machine to which you want to
## send the data files ENVISION=192.168.1.20
## Enter the directories where the data files, which you need to send, exist. Separate
## multiple directories with a colon (:). This script must have read permissions
## to the directories.
## Example for multiple folders DATA_DIRECTORY=/var/log/:/var/log/audit
DATA_DIRECTORY=/var/log/
## The directory on the enVision box where the files should be written to. This directory
## is relative to the enVision/ftp_files directory. If the directory name contains a
## space it will need to be double escaped. For example, if the directory name is
## “name with spaces”, the variable needs to be set to “name with spaces”.
ENVISION_DIRECTORY=Squid_192.168.1.63
## The script keeps its persistent information in a directory. The
## script must have read and write permissions to this directory.
NIC_DIRECTORY=/usr/local/nic
## TRANSFER_METHOD=SFTP/SCP/FTP
## Select the method used to transfer the files to enVision. SFTP is recommended.
## valid options are FTP, SFTP and SCP
TRANSFER_METHOD=SFTP
## Enter a username (ftp default: anonymous; SFTP/SCP default: nic_sshd)
USERNAME=nic_sshd
## Enter a password (anonymous connections accept any password)
PASSWORD=RSAlab@12345
## Enter the identity/private key file for the user specified above user
## default is $HOME/.ssh/id_rsa
IDENTITY=~/.ssh/id_rsa
## Enter the file matching specification. “*” will send any files in the directory. Separate
## multiple fielnames with a colon (:).
## Example for multiple files::
## …read more Source: FULL ARTICLE at The UNIX and Linux Forums
When i run a script in linux. It shows the following error.
‘icsftpagent.sh: line 114: syntax error near unexpected token `
‘icsftpagent.sh: line 114: `Nicsftp()
My Script is as follows:
#!/bin/bash
#### Copyright Notice:
####
#### Copyright (c) 2007 Network Intelligence Corporation
####
#### Warning: This computer program is protected by copyright law and
#### international treaties. Unauthorized reproduction or distribution
#### of this program, or any portion of it, may result in severe civil
#### and criminal penalties, and will be prosecuted to the maximum
#### extent possible under the law.
####
#### RSA, The Security Division of EMC – Automated FTP/SCP/SFTP Script v2.7.11
####
###################
####
#### Begin User configuration
####
##########
########
######
####
#SILENT MODE
#produce no output to the console;
#set this to true when running from cron
#to reduce emails sent to root. SILENT=true
# Have the Solaris POSIX compliant binaries first in the path.
# The /usr/bin directory in Solaris doesn’t have POSIX compliant
# binaries. This is particularly a problem for the awk command we are
# using. (ECE-138)
#PATH=/usr/xpg6/bin:/usr/xpg4/bin:/usr/css/bin:$PATH
## Enter the hostname/IP address of the enVision machine to which you want to
## send the data files ENVISION=192.168.1.20
## Enter the directories where the data files, which you need to send, exist. Separate
## multiple directories with a colon (:). This script must have read permissions
## to the directories.
## Example for multiple folders DATA_DIRECTORY=/var/log/:/var/log/audit
DATA_DIRECTORY=/var/log/
## The directory on the enVision box where the files should be written to. This directory
## is relative to the enVision/ftp_files directory. If the directory name contains a
## space it will need to be double escaped. For example, if the directory name is
## “name with spaces”, the variable needs to be set to “name with spaces”.
ENVISION_DIRECTORY=Squid_192.168.1.63
## The script keeps its persistent information in a directory. The
## script must have read and write permissions to this directory.
NIC_DIRECTORY=/usr/local/nic
## TRANSFER_METHOD=SFTP/SCP/FTP
## Select the method used to transfer the files to enVision. SFTP is recommended.
## valid options are FTP, SFTP and SCP
TRANSFER_METHOD=SFTP
## Enter a username (ftp default: anonymous; SFTP/SCP default: nic_sshd)
USERNAME=nic_sshd
## Enter a password (anonymous connections accept any password)
PASSWORD=RSAlab@12345
## Enter the identity/private key file for the user specified above user
## default is $HOME/.ssh/id_rsa
IDENTITY=~/.ssh/id_rsa
## Enter the file matching specification. “*” will send any files in the directory. Separate
## multiple fielnames with a colon (:).
## Example for multiple files::
## FILESPEC=*.log:xyz.log …read more Source: FULL ARTICLE at The UNIX and Linux Forums
I have been asked to see if we can restrict SFTP access to authorised users only. There will be business users who will log on with SSH, but they are locked into a menu. They will have write access to the production data to do their job, but we don’t want them to have access to read/write the files with SFTP or anything else for that matter.
For plain FTP, we would use the /etc/ftpusers file and re-create it each night with all users in /etc/passwd except those in the allowed list. Not clever, but it worked.
We’re running RHEL / Centos 6.3 and the server is running vsftp is installed for plain FTP along with openssh-server-5.3p1-81.el6_3.x86_64 The sshd_config file defines sftp as starting up /usr/libexec/openssh/sftp-server
Any suggestions? Badly, the users home directory is a common area with the application & data below it, so I can’t just enforce the chroot jail. User SSH login is by userid/password rather than certificate. Not sure if that helps or hinders.
I have a sql script which i need to embed in a shell. The sql (oracle) script will generate a .csv file in some Unix directory. the approximate file size is around 10 mb which i need to upload to an sftp server. My concern here is how to make sure that the file generation is completed . Manually when i am running the script its taking 30 mins and the generated file size goes on increasing. Depending upon the table data the script may run for a long time too increasing the file size.
Handy Backup is utilitarian in the best sense; it’s a backup program with a no-nonsense interface and a boatload of features. Despite its plain countenance, one of its iterations is sure to appeal to IT types and smart consumers. I looked at Handy Backup Free, which is… free.
1. There’s not a lot to look at, but there’s power behind the Handy Backup grille.
Handy Backup Free is easy to use and lets you selects files as well as repositories for backing up. Repositories are folders or accounts such as My Documents, an FTP, WebDav, Amazon S3, etc. It’s a little odd to see the latter items listed under a backup list, but it’s also nice. You can back up to and restore data from local drives, CD/DVD/BD, FTP, and across a network.
You create a backup, restore, or synch task in Handy Backup Home using step-by-step wizards. These are easy to use, and once a task has been defined you can edit all the options directly from a multiple-paned dialog. To skip the wizard, you can simply duplicate a task and edit the pertinent options. Said options include full, incremental, differential backups; compressing the backup to encrypted zip files; scheduling; and running tasks before or after a job.
Handy Backup also comes in a $39 Home, $99 Professional, $199 Small Server, and $599 Server editions. Home is the latest 7.x version, while Pro adds disk imaging, backing up to SFTP servers, and ODBC database backup. The Small Server edition backs up numerous business and enterprise-level databases such as Microsoft Exchange data, Oracle, and more. The full Server version has all that plus the ability to back up multiple PCs to a central location.
I need to transfer the files from the Remote server using SFTP. While i transfer the file, the time stamp of the file need not to be changed. Ineed to transfer the file as without change in its time stamp.
Is the any option or commands available. pl let me know…
I need to write a script which can send files via sftp communication continously for half an hour or any given duration of time. I have already written a batch file to send multiple file via SFTP.
but I need to know how can we set a duration of half an hour through shell script. Can we use sleep command for this.
The $300 Synology DS213air is a decent two-bay NAS box whose main claim to fame is its ability to perform as an 802.11 b/g Wi-Fi access point. The unit streams media quite well; however, its name is a bit misleading in that the DS213air has more in common with the $200 DS212j than the significantly faster $300 DS213. The DS213air’s wireless feature isn’t all that unique either, since you can turn add similar functionality to any current Synology NAS box using an inexpensive third-party USB 802.11 adapter. On the upside, this router sports Synology’s usual bountiful array of software features.
The DS213air uses a 1.6GHz Marvell Kirkwood mv6282 single-core CPU, and it sports 256MB of system memory. Our review unit arrived populated with two 1TB Seagate Barracuda drives in RAID 1 (mirrored). Using those components, the DS213air wrote our 10GB mix of smaller files and folders at 35.5MBps and read them at 38.3MBps. With our single large 10GB file, its performance increased to 43.6MBps writing and 74.5MBps reading. Those numbers aren’t bad, but they’re slower than what we see from most of the competition these days.
I also tested the DS213air’s streaming ability with a third-generation iPad, an Asus S7 laptop, and a slower Acer 7250 laptop. Music, photos, and even 1080p video streamed smoothly to all, though as with any Wi-Fi, your proximity and environment will impact results. Note that you must first configure the DS213air using wired Ethernet, pull the Ethernet cable, power down, and then power up again before the DLNA server will choose the Wi-Fi rather than wired network.
Synology’s operating system (along with QNAP‘s) stands head and shoulders above the rest of the competition for breadth of features. The short list includes DHCP, mail and website serving, DLNA and iTunes media serving, free one-camera video surveillance, Web-based photo/video/music serving, FTP, SFTP, HTTPS, and the usual administration features. That makes it a small business server in everything but name. A demo on Synology’s Web site lets you play with many of the features. You can check it out here.
i need to transfer some files from windows server to unix server using SFTP. but before transferring the files, i need to check the
existence of a particular file in the remote directory (say r_dir1). if the file is present, then SFTP all the files.
after SFTPing the files from the remote directory (r_dir1) to unix directory, i need to move the files from remote directory (r_dir1)
to some other remote directory (say dir2) in the same windows server only.
sftp ${REMOTE_USER}@${REMOTE_MACHINE} <<EOF
cd ${REMOTE_DIR}
if [[ -f “$REMOTE_DIR”/”$FILE_NAME_TO_CHECK” ]]; then
get * # downloading all the files
mv *
else
echo “$FILE_NAM the E_TO_CHECK doesn’t exist so cant copy other files”
fi
————————————————————————————————————–
# files are getting SFTPed to the unix server but
errors:
1:- showing “if” and “else” statements as invalid commands
2:- showing “mv” command as invalid
please, some body provide me a solution.. i need it urgently
I have ssh connection between two servers for a functional Id for SFTP purpose.
I aim is to setup this for is only work when below command is used by a .ksh script.
ssh userid@servername:/directory
Unfortunately users who have access to functional id are manually using above command and start moving files between these two servers. I want to restrict this manual login and activate only for scripts that contains above command.
By Nitin VarshneyaHi,I am using following code for FTP in shell script file and it is working.Now I want to migrate from FTP to SFTP.What code changes/steps I have to perform for SFTP ?