[CS:S/CS:GO] FTPLIB

Please post any questions about developing your plugin here. Please use the search function before posting!
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

[CS:S/CS:GO] FTPLIB

Postby cssbestrpg » Mon Apr 24, 2023 6:44 pm

Hi, i have issue with my code, i tried make code that suppose check each map start is there missing nav file from the fastdownload, if there is missing nav file, it keeps giving me these errors:

Code: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
  File "../addons/source-python/plugins/fastdl/fastdl.py", line 33, in check_fastdl_files()
    ftp.storbinary(f'STOR {file}', file)
  File "../addons/source-python/Python3/ftplib.py", line 502, in storbinary
    with self.transfercmd(cmd, rest) as conn:
  File "../addons/source-python/Python3/ftplib.py", line 397, in transfercmd
    return self.ntransfercmd(cmd, rest)[0]
  File "../addons/source-python/Python3/ftplib.py", line 363, in ntransfercmd
    resp = self.sendcmd(cmd)
  File "../addons/source-python/Python3/ftplib.py", line 271, in sendcmd
    return self.getresp()
  File "../addons/source-python/Python3/ftplib.py", line 244, in getresp
    raise error_perm(resp)

ftplib.error_perm: 550 <_io.BufferedReader name=Path('csgo/maps/$2000$.nav')>: No such file or directory


Here is the code:

Syntax: Select all

import os
import ftplib
from path import Path
from core import GAME_NAME
from listeners import OnLevelInit

BASE_PATH = Path(f'{GAME_NAME}/maps')

FTP_HOST = ''
FTP_USER = ''
FTP_PASSWORD = ''
FTP_WEB_FOLDER_PATH = ''

@OnLevelInit
def map_start(current_map):
check_fastdl_files()

def check_fastdl_files():
ftp = ftplib.FTP(timeout=10)

ftp.connect(FTP_HOST, 21)
ftp.login(FTP_USER, FTP_PASSWORD)

ftp.cwd(f'{FTP_WEB_FOLDER_PATH}/{GAME_NAME}/maps')

files = ftp.nlst()

for maps in os.listdir(f'{GAME_NAME}/maps/'):
if maps.endswith('.nav'):
map_to_check = maps + '.bz2'
if not map_to_check in files:
with open(BASE_PATH.joinpath(maps), 'rb') as file:
ftp.storbinary(f'STOR {file}', file)
print(f'[FTP]: Uploaded {file}')
ftp.quit()


I don't understand why it gives me that error, what is wrong of my code?

I checked that the map file does exists in the server
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [CS:S/CS:GO] FTPLIB

Postby satoon101 » Mon Apr 24, 2023 11:20 pm

If I am reading this correctly, I think both strings of {file} should be {maps} because file is an open file object.
Image
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [CS:S/CS:GO] FTPLIB

Postby cssbestrpg » Tue Apr 25, 2023 9:30 am

It gave different error:

Code: Select all

[2023-04-25 12:29:25]: ftp.storbinary(f'STOR {maps}', maps)
[2023-04-25 12:29:25]: File "../addons/source-python/Python3/ftplib.py", line 504, in storbinary
[2023-04-25 12:29:25]: buf = fp.read(blocksize)
[2023-04-25 12:29:25]: AttributeError: 'str' object has no attribute 'read'


Edit:

Managed to fix the error after changing code to this:

Syntax: Select all

import os
import ftplib
from path import Path
from core import GAME_NAME
from listeners import OnLevelInit

BASE_PATH = Path(f'{GAME_NAME}/maps')

FTP_HOST = ''
FTP_USER = ''
FTP_PASSWORD = ''
FTP_WEB_FOLDER_PATH = ''

@OnLevelInit
def map_start(current_map):
check_fastdl_files()

def check_fastdl_files():
ftp = ftplib.FTP(timeout=10)

ftp.connect(FTP_HOST, 21)
ftp.login(FTP_USER, FTP_PASSWORD)

ftp.cwd(f'{FTP_WEB_FOLDER_PATH}/{GAME_NAME}/maps')

files = ftp.nlst()

for maps in os.listdir(f'{GAME_NAME}/maps/'):
if maps.endswith('.nav'):
map_to_check = maps + '.bz2'
if not map_to_check in files:
with open(BASE_PATH.joinpath(maps), 'rb') as file:
ftp.storbinary(f'STOR {maps}', file)
print(f'[FTP]: Uploaded {maps}')
ftp.quit()

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 28 guests