Archive

Posts Tagged ‘ftp’

PHP CLI FTP uploader

February 21st, 2009 Arthur Gressick No comments

So I wanted to create a automated FTP uploader for the project I was working on. I set a CRONTAB to execute it and then hooked up a database as well. 

Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/php -q
<?php
#script used for uploading file to a server
//------ Begin Programming
 
$ftp_server = "subdomain.server.com";
$ftp_retries = "5";
$ftp_delay = "3";
$ftp_user = "user";
$ftp_pass = "password";
 
//This worked on the server
$source_directory = "/home/user/videos/flv/";
$remote_directory = "/httpdocs/movies/";
 
//mysql connection
define ('DB_User', 'user');
define ('DB_Password', 'password');
define ('DB_Host', 'x.x.x.x');
define ('DB_Name', 'db_name');
 
$dbc = mysql_connect (DB_Host, DB_User, DB_Password) OR
die ('Could not connect to MySQL Server: ' . mysql_error() );
mysql_select_db (DB_Name) or
die ('Could not select the database: ' . mysql_error() );
 
//do a query
$sql_query = "your query";
$result = @mysql_query ($sql_query);
$videos = mysql_fetch_array ($result, MYSQL_ASSOC);
$counter = mysql_num_rows($result);
 
if ($counter &gt; 0) {
 
//mark the as processing
$sql_query = "UPDATE SCRIPT";
$result = @mysql_query ($sql_query);
 
//
$conn_id = ftp_connect($ftp_server);
 
$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);
 
$source = $source_directory.$videos['processed_file'].".flv";
$remote = $remote_directory.$videos['processed_file'].".flv";
 
if (ftp_put($conn_id, $remote, $source, FTP_BINARY)) {
//            echo "successfully uploaded $source\n";
} else {
//mark file to reupload again
$sql_query = "UPDATE SCRIPT";
$result = @mysql_query ($sql_query);
//            echo "There was a problem while uploading $source to $remote\n";
}
 
 // Close connection
ftp_close($conn_id);
}
?>

Categories: PHP, PHP CLI, Ubuntu 8.x Server Tags: , , , ,

Ubuntu VSFTP

February 12th, 2009 Arthur Gressick No comments

So this one is very easy to do and works very well for most installations. It is using the VSFTP Service.

apt-get install vsftpd

Then change the following in the file /etc/vsftpd.conf

anonymous_enable=NO
local_enable=YES
write_enable=YES
chroot_local_user=YES

Now you need to reboot the service

/etc/init.d/vsftpd start

This works very well with user accounts on the machine.

UPDATE:
I had some problems with people posting files and the permission where always read only for websites. Just add this to the CONF file and things should work better

chmod_enable=YES

Categories: Ubuntu 8.x Server Tags: ,