View Full Version : Unix .sh script from Win to Unix (FTP)
The One
June 16th, 2010, 07:40 PM
Ok boys............
I need a unix .sh script that FTP's from Windows to A Unix box and not the other way round.......
I need it to connect to a windows machine and pull files to the Unix box
What is needed is Not a windows .bat script but a Unix .sh script
.????????????...
.
Unbreakable
June 16th, 2010, 08:26 PM
http://www.aboutdebian.com/
hope this helps
The One
June 16th, 2010, 11:20 PM
http://www.aboutdebian.com/
hope this helps
Thanks a bunch for the link ma8....... But truest me, u won't find much about what I'm asking on the net.......
.
Phoenix
June 16th, 2010, 11:48 PM
well you dont need a script. depending on what unix distribution you are running and depends on how you go about it. However, most unix systems by default offer the 'ftp [host]' command. So open up a terminal if your running linux and type 'ftp [host]' obviously replacing [host] with the IP or hostname of the windows machine you wish to connect to.
remember that you need to be running an FTP server on the windows machine in order to accept ftp connections.
if u want an easier method to transfer files, try FileZilla.
The One
June 17th, 2010, 12:32 AM
well you dont need a script. depending on what unix distribution you are running and depends on how you go about it. However, most unix systems by default offer the 'ftp [host]' command. So open up a terminal if your running linux and type 'ftp [host]' obviously replacing [host] with the IP or hostname of the windows machine you wish to connect to.
remember that you need to be running an FTP server on the windows machine in order to accept ftp connections.
if u want an easier method to transfer files, try FileZilla.
Yes I'm aware of that process....... But that would require humen intervention meaning it need to be manually don't......it's doesn't work if u automate it............its doesn't allow u to log onto the windows machine even if u hard code the user and pass
Your talking about the standard way...which is quite strate forward......but automating it just doesn't work....the script needs to be on the unix box.....it's hp unix
My script is working fine from unix to unix and from windows to unix.....but windows has security holes......so I need to do it the other way......
Filezilla runs onnthe client windows machine.....again I need something running on unix to automate and connect to windows then FTP to unix........nothing manual all auto
.
Unbreakable
June 17th, 2010, 02:22 AM
write a bash script of what you want to do then tell it to loop in order to get action automated
Phoenix
June 17th, 2010, 08:07 AM
Yes I'm aware of that process....... But that would require humen intervention meaning it need to be manually don't......it's doesn't work if u automate it............its doesn't allow u to log onto the windows machine even if u hard code the user and pass
Your talking about the standard way...which is quite strate forward......but automating it just doesn't work....the script needs to be on the unix box.....it's hp unix
My script is working fine from unix to unix and from windows to unix.....but windows has security holes......so I need to do it the other way......
Filezilla runs onnthe client windows machine.....again I need something running on unix to automate and connect to windows then FTP to unix........nothing manual all auto
.
FileZilla works on all platforms bro not just windows. give it a try.
The One
June 17th, 2010, 10:00 AM
FileZilla works on all platforms bro not just windows. give it a try.
Thanks for you feedback, but forget about a GUI interface (forget about FileZilla)................thats why i asked about a script in the first place.................no tools ma8, just pure UNIX Scripting..............which would be crontab'd..............
AnyOne....
.
The One
June 17th, 2010, 02:48 PM
this is my UNIX to UNIX script.......................................i need something simuler that would do UNIX to Windows
# Created by: ############
#
# Creation Date: ###########
#
# FTP script from ####### to ####### with log file
#
#
LOG_FILE=/path/file_name.log
FTP_LOGIN="user_id"
FTP_PASSWORD="user_password"
HOST="ip_address"
cd "directory_path"
YYMMDD=`/bin/date '+%y%m%d' | sed 's/ //'`
FILE_NAME=ZZ$YYMMDD.E01
echo $FILE_NAME
# Activity file to be named using same convention as regular
# Activity files and should be places within the same directory as well
>> $LOG_FILE
echo "====================================Start ftp==================================" >> $LOG_FILE
ftp -v $HOST >> $LOG_FILE
user $FTP_LOGIN $FTP_PASSWORD
cd "directory_path" >> $LOG_FILE
pwd >> $LOG_FILE
mv "old_file_name" $FILE_NAME >> $LOG_FILE
put "file_name" >> $LOG_FILE
quit
echo '"file_name" file transmitted from ########' >> $LOG_FILE
echo >> $LOG_FILE
echo "====================================End ftp==================================" >> $LOG_FILE
EOF
Waaaannnnn hum elle tal333eennn feehaaaaaaa.....yaaalaaa laaaaa.....this is some real work...show me what u can do.....System Specialst come on..............
.
Ghareeb_ilDar
June 17th, 2010, 03:35 PM
We'll i'm not a system specialist or anything but correct me if i'm wrong... you basically need a script for a unix box that pulls files from a windows box?
The One
June 17th, 2010, 05:18 PM
We'll i'm not a system specialist or anything but correct me if i'm wrong... you basically need a script for a unix box that pulls files from a windows box?
yup thats right..........
.
The Italian
June 17th, 2010, 06:46 PM
from the unix side you can do a wget targeting the windows files
ps make sure to put a timeout on the script in case access is denied so it won't run an infinite loop
The Italian
June 18th, 2010, 05:30 PM
btw this is what i'm using to dump backups into an S3
<?php
set_time_limit(0);
/************************************************** *********
|
| server backup script
|
************************************************** *********/
$nDays = 5; // How many days of backups to keep?
/**************************************
| MySQL variables
***************************************/
$bBackupMySQL = true; // Do you want to backup MySQL databases?
$mysql = '/usr/bin/mysql';
$mysqldump = '/usr/bin/mysqldump';
$mysql_server = 'localhost';
$mysql_username = 'uname';
$mysql_password = 'password';
/**************************************
| httpdocs variables
***************************************/
$bBackuphttpd = true; // Do you want to backup httpd (web) docs?
$cVhostsDir = '/var/www/vhosts/'; // Include trailing slash
/**************************************
| Used to compress backup data
***************************************/
$tar = '/bin/tar';
/**************************************
| Where you'll be running the script, most likely
***************************************/
$workingDir = '/root/';
/**************************************
| Amazon S3 set-up
***************************************/
$bAMZNS3 = true; // Backup to S3?
if ($bAMZNS3) {
$accessKeyId = 'xxx';
$secretAccessKey = 'xxx';
$bucketName = 'xxx';
/**
* Amazon S3 PHP class
*
* @link http://undesigned.org.za/2007/10/22/amazon-s3-php-class
*/
include('s3-php5-curl/S3.php');
} // ends if ($bAMZNS3)
/**************************************
| FTP set-up
***************************************/
$bFTP = false; // Backup to FTP?
if ($bFTP) {
$ftp_server = '127.0.0.1';
$ftp_username = 'ftpuser';
$ftp_password = 'ftppass!';
} // ends if ($bFTP)
/**************************************
| What suffix to add to filenames
| if daily, make it the date
| if you're going to run this hourly, or 2x / day, make it unique
***************************************/
$suffix = date("Ymd");
/************************************************** *********
|
| Done editing script
|
************************************************** *********/
chdir($workingDir);
$oMysql = mysql_connect($mysql_server, $mysql_username, $mysql_password);
if ($bAMZNS3) {
$s3 = new S3($accessKeyId, $secretAccessKey);
} // ends if ($bAMZNS3)
if ($bFTP) {
$oFTP = ftp_connect($ftp_server);
ftp_login($oFTP, $ftp_username, $ftp_password);
} // ends if ($bFTP)
///////////////////////////////////////////////////////////
// Mysql Database Backups
///////////////////////////////////////////////////////////
if ($bBackupMySQL) {
// Get a list of the databases
$oDBList = mysql_list_dbs($oMysql);
while ($rsData = mysql_fetch_object($oDBList)) {
$cDatabase = $rsData->Database;
$cSQLFilename = $cDatabase . '_' . $suffix . '.sql';
$cTarGZFilename = $cSQLFilename . '.tar.gz';
// Dump them
$cliResult = `$mysqldump -u$mysql_username -p$mysql_password $cDatabase > $cSQLFilename`;
// Tar them up
$cliResult = `$tar -cpzf $cTarGZFilename $cSQLFilename`;
unlink($cSQLFilename);
if ($bAMZNS3) {
// Send to Amazon
$s3->putObjectFile($cTarGZFilename, $bucketName, $cTarGZFilename, S3::ACL_PRIVATE);
} // ends if ($bAMZNS3)
if ($bFTP) {
// FTP to server
ftp_put($oFTP, $cTarGZFilename, $cTarGZFilename, FTP_BINARY);
} // ends if ($bFTP)
echo("Saved $cTarGZFilename\n");
// Cleanup
unlink($cTarGZFilename);
} // ends while ($rsData = mysql_fetch_object($oDBList))
} // ends if ($bBackupMySQL)
///////////////////////////////////////////////////////////
// Ends MySQL Backups
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
// Mysql httpdocs Backups
///////////////////////////////////////////////////////////
if ($bBackuphttpd) {
// Get a list of the sites
chdir($cVhostsDir);
if ($oDir = opendir($cVhostsDir)) {
while (false !== ($cFilename = readdir($oDir))) {
if (!in_array($cFilename, array('.', '..', 'chroot', 'default', '.skel'))) {
$cTarGZFilename = $cFilename . '_' . $suffix . '.tar.gz';
$cTarGZPath = $workingDir . $cTarGZFilename;
$cSourceFiles = $cFilename . '/httpdocs/';
// Tar them up
`$tar -cpzf $cTarGZPath $cSourceFiles`;
if ($bAMZNS3) {
// Send to Amazon
$s3->putObjectFile($cTarGZPath, $bucketName, $cTarGZFilename, S3::ACL_PRIVATE);
} // ends if ($bAMZNS3)
if ($bFTP) {
// FTP to server
ftp_put($oFTP, $cTarGZFilename, $cTarGZPath, FTP_BINARY);
} // ends if ($bFTP)
echo("Saved $cTarGZFilename\n");
// Cleanup
unlink($cTarGZPath);
} // ends if (!in_array($cFilename, array(...
} // ends while (false !== ($cFilename = readdir($oDir)))
closedir($oDir);
} // ends if ($oDir = opendir('/var/www/vhosts/'))
chdir($workingDir);
} // ends if ($bBackuphttpd)
///////////////////////////////////////////////////////////
// Ends httpdocs backups
///////////////////////////////////////////////////////////
echo("Done writing backup - starting cleanup.\n");
///////////////////////////////////////////////////////////
// Cleanup old files from the server
///////////////////////////////////////////////////////////
if ($bAMZNS3) {
$aS3Files = $s3->getBucket($bucketName);
while (list($cFilename, $rsFileData) = each($aS3Files)) {
if ($rsFileData['time']+($nDays*24*60*60) < time(void)) {
$s3->deleteObject($bucketName, $cFilename);
} // ends if ($tsModTime+432000 < time(void))
} // ends while (list($cFilename, $rsFileData) = each($s3->getBucket($bucketName)))
} // ends if ($bAMZNS3)
if ($bFTP) {
$list=@ftp_rawlist($oFTP, '.') ;
$items=array() ;
foreach($list as $_)
preg_replace(
'`^(.{10}+)(\s*)(\d{1})(\s*)(\d*|\w*)'.
'(\s*)(\d*|\w*)(\s*)(\d*)\s'.
'([a-zA-Z]{3}+)(\s*)([0-9]{1,2}+)'.
'(\s*)([0-9]{2}+):([0-9]{2}+)(\s*)(.*)$`Ue',
'$items[]=array(
"rights"=>"$1",
"number"=>"$3",
"owner"=>"$5", "group"=>"$7",
"file_size"=>"$9",
"mod_time"=>"$10 $12 $14:$15",
"file"=>"$17",
"type"=>print_r((preg_match("/^d/","$1"))?"dir":"file",1));',
$_) ; # :p
// Remove anything older than 5 days
foreach ($items as $rsFTPFile) {
$cFilename = trim($rsFTPFile['file']);
$tsModTime = strtotime($rsFTPFile['mod_time']);
if ($tsModTime+($nDays*24*60*60) < time(void)) {
ftp_delete($oFTP, $cFilename);
} // ends if ($tsModTime+432000 < time(void))
} // ends foreach ($items as $rsFTPFile)
ftp_close($oFTP);
} // ends if ($bFTP)
///////////////////////////////////////////////////////////
// Ends cleanup
///////////////////////////////////////////////////////////
?>
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.