Rifts Posted April 22, 2011 Share Posted April 22, 2011 Hey guys I don't know if this is possible but here is what I need to do. I have a log (txt file) on my computer I need it to automatically upload itself to my server every X minutes. Is this possible at all? Quote Link to comment https://forums.phpfreaks.com/topic/234473-strange-question-updating-file-automatically/ Share on other sites More sharing options...
gizmola Posted April 22, 2011 Share Posted April 22, 2011 Of course. What operating system is your computer running? Quote Link to comment https://forums.phpfreaks.com/topic/234473-strange-question-updating-file-automatically/#findComment-1205044 Share on other sites More sharing options...
PFMaBiSmAd Posted April 22, 2011 Share Posted April 22, 2011 to my server It would probably help if you defined "my server"? Is this a web server? An FTP server? As that would define what protocol(s) could be used to accomplish this. It would also help if you defined - "my computer"? What operating system? How small is x seconds? Does it already have php installed (either as CLI or as a web server extension)? Quote Link to comment https://forums.phpfreaks.com/topic/234473-strange-question-updating-file-automatically/#findComment-1205045 Share on other sites More sharing options...
Rifts Posted April 22, 2011 Author Share Posted April 22, 2011 oh sorry the file is on my local machine windows 7 and I have a hosting server with godaddy which I use FTP with. I would like to have the updated log file every 3-5 mins. im just not sure how i can do this or what i would need Quote Link to comment https://forums.phpfreaks.com/topic/234473-strange-question-updating-file-automatically/#findComment-1205067 Share on other sites More sharing options...
gizmola Posted April 23, 2011 Share Posted April 23, 2011 Windows has a task scheduler application that lets you setup the equivalent of a cron job. You can make a simple batch file that calls the windows ftp command line client. If you open up a cmd window and type ftp --help you'll see something like this: C:\Users\David>ftp --help Transfers files to and from a computer running an FTP server service (sometimes called a daemon). Ftp can be used interactively. FTP [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-A] [-x:sendbuffer] [-r:recvb fer] [-b:asyncbuffers] [-w:windowsize] [host] -v Suppresses display of remote server responses. -n Suppresses auto-login upon initial connection. -i Turns off interactive prompting during multiple file transfers. -d Enables debugging. -g Disables filename globbing (see GLOB command). -s:filename Specifies a text file containing FTP commands; the commands will automatically run after FTP starts. -a Use any local interface when binding data connection. -A login as anonymous. -x:send sockbuf Overrides the default SO_SNDBUF size of 8192. -r:recv sockbuf Overrides the default SO_RCVBUF size of 8192. -b:async count Overrides the default async count of 3 -w:windowsize Overrides the default transfer buffer size of 65535. host Specifies the host name or IP address of the remote host to connect to. Notes: - mget and mput commands take y/n/q for yes/no/quit. - Use Control-C to abort commands. The two important arguments to notice are -n and -s. You can use the -n to turn off the automatic login attempt and the -s to specify a file of commands to be automatically run. So you can make a simple batch file that starts ftp with these parameters and a file that has the commands to PUT the file on the ftp server. ftpfile.bat ftp -n -s:ftp.txt ftp.server.com ftp.txt user yourusername ftpuserpassword binary literal pasv put thefilename.txt quit Then setup this batch file to be called in the windows scheduler application. This is a simple barebones solution which admittedly has absolutely no error checking, but it will get the job done in most cases. There are scores of more robust solutions out there, but a lot might be overkill for what you're doing. Quote Link to comment https://forums.phpfreaks.com/topic/234473-strange-question-updating-file-automatically/#findComment-1205105 Share on other sites More sharing options...
Rifts Posted April 23, 2011 Author Share Posted April 23, 2011 wow you are amazing! I'm going to try this out as soon and I can get my application to starting creating logs.txt files correctly! thanks again Quote Link to comment https://forums.phpfreaks.com/topic/234473-strange-question-updating-file-automatically/#findComment-1205198 Share on other sites More sharing options...
Rifts Posted April 28, 2011 Author Share Posted April 28, 2011 in this part ftp.txt Code: user yourusername ftpuserpassword binary literal pasv put thefilename.txt quit what is binary and literal pasv Quote Link to comment https://forums.phpfreaks.com/topic/234473-strange-question-updating-file-automatically/#findComment-1207288 Share on other sites More sharing options...
gizmola Posted April 28, 2011 Share Posted April 28, 2011 binary tells ftp to use binary transfer mode, rather than the default of ascii. If you have text, you might want to omit that line. literal pasv tells the server to use pasv mode. Without going into a long explanation, ftp transfers won't work if the client is behind a nat'd firewall, so it's best to set this mode on in most cases. Quote Link to comment https://forums.phpfreaks.com/topic/234473-strange-question-updating-file-automatically/#findComment-1207293 Share on other sites More sharing options...
Rifts Posted April 28, 2011 Author Share Posted April 28, 2011 I need it to overwrite the older version on the FTP when doing this do you know if it will do that? Quote Link to comment https://forums.phpfreaks.com/topic/234473-strange-question-updating-file-automatically/#findComment-1207332 Share on other sites More sharing options...
btherl Posted April 28, 2011 Share Posted April 28, 2011 I need it to overwrite the older version on the FTP when doing this do you know if it will do that? Probably. The best way to find out is to try. Quote Link to comment https://forums.phpfreaks.com/topic/234473-strange-question-updating-file-automatically/#findComment-1207351 Share on other sites More sharing options...
gizmola Posted April 28, 2011 Share Posted April 28, 2011 Yes put will overwrite an existing file, so long as the permissions allow it. Just in case you were wondering, the put command is a commonly used alias for the FTP STOR command. FTP like a lot of internet protocols has a series of RFC documents that describe it. If you look in the FTP RFC #959 for the STOR command you'll find this: STORE (STOR) This command causes the server-DTP to accept the data transferred via the data connection and to store the data as a file at the server site. If the file specified in the pathname exists at the server site, then its contents shall be replaced by the data being transferred. A new file is created at the server site if the file specified in the pathname does not already exist. Quote Link to comment https://forums.phpfreaks.com/topic/234473-strange-question-updating-file-automatically/#findComment-1207360 Share on other sites More sharing options...
Rifts Posted April 28, 2011 Author Share Posted April 28, 2011 ok everything is almost working. im running into this error 425 Could not open data connection to port 1203: Connection refused and the port keeps changing everytime i retry Quote Link to comment https://forums.phpfreaks.com/topic/234473-strange-question-updating-file-automatically/#findComment-1207364 Share on other sites More sharing options...
btherl Posted April 28, 2011 Share Posted April 28, 2011 You can try removing the "literal pasv" and see if that works. It's normal for the port to change - ftp opens a new connection on a new port number for every file transferred. Quote Link to comment https://forums.phpfreaks.com/topic/234473-strange-question-updating-file-automatically/#findComment-1207387 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.