# How to copy from S3 to Windows shared drive/folder

**URL:** <https://forum.serverless.com/t/how-to-copy-from-s3-to-windows-shared-drive-folder/11075>\
**Category:** Serverless Framework\
**Tags:** aws, lambda\
**Created:** [April 9, 2020, 10:29pm UTC](https://forum.serverless.com/t/how-to-copy-from-s3-to-windows-shared-drive-folder/11075 "2020-04-09T22:29:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonatansmith](https://avatars.discourse-cdn.com/v4/letter/j/cdc98d/32.png) [@jonatansmith](https://forum.serverless.com/u/jonatansmith)\
**Post date:** [April 9, 2020, 10:29pm UTC](https://forum.serverless.com/t/how-to-copy-from-s3-to-windows-shared-drive-folder/11075/1 "2020-04-09T22:29:45Z")

</div>

I need to copy a small CSV file from my S3 bucket to on-prem Windows Shared Drive which is connected through VPN.

Can it be done using Lambda? Or should I try another aproach?

Origin: S3 bucket  
Transporter: serverless  
Destination: Windows Shared Folder/Drive

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![jonatansmith](https://avatars.discourse-cdn.com/v4/letter/j/cdc98d/32.png) [@jonatansmith](https://forum.serverless.com/u/jonatansmith)\
**Post date:** [April 13, 2020, 2:40pm UTC](https://forum.serverless.com/t/how-to-copy-from-s3-to-windows-shared-drive-folder/11075/2 "2020-04-13T14:40:12Z")

</div>

Hi,  
If anyone need, I was able to copy from Lambda to Shared Folder using a python library “PySMB”

I used code from here to test list dir: [https://gist.github.com/joselitosn/e74dbc2812c6479d3678](https://gist.github.com/joselitosn/e74dbc2812c6479d3678)

Also, these docs: [https://pysmb.readthedocs.io/en/latest/api/smb\_SMBConnection.html](https://pysmb.readthedocs.io/en/latest/api/smb_SMBConnection.html)

To copy, I used storeFile method.

Here the code I’ve used:  
Obs.: It is need to upload to Lambda folder pysmb and pyasn1 librarys

```
import json
import boto3

from smb.SMBConnection import SMBConnection

def lambda_handler(event, context):
    
    conn = SMBConnection(userID, password, client_machine_name, server_name, domain=domain_name, use_ntlm_v2=True,
                     is_direct_tcp=True)
    
    conected = conn.connect(server_ip, 445)
    print('contected?')
    print(conected)
    

    files = conn.listPath('operacoes_varejo$', 'Carga Consignado', search=65591, pattern='*', timeout=30)
   
    #print files
    for file in files:
        print(file.filename)
    
    #Copy from s3  
    s3 = boto3.client('s3')
    objects3tmp = s3.download_file('bucketname', 'keyname', '/tmp/file')
    print('Downloaded..')
    
    #open rb (read binary)
    file_obj = open('/tmp/file', 'rb')
    
    #upload files to shared drive
    conn.storeFile('first_level_shared_folder', 'second_level/filename', file_obj)    
  
    
    conn.close()

    
    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }
```

---

<div class="post-metadata">

**Author:** ![HumaAWS](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/humaaws/32/5179_2.png) [@HumaAWS](https://forum.serverless.com/u/HumaAWS)\
**Post date:** [February 2, 2021, 2:45pm UTC](https://forum.serverless.com/t/how-to-copy-from-s3-to-windows-shared-drive-folder/11075/3 "2021-02-02T14:45:21Z")

</div>

how do we copy files from shared folder to S3 ? other way round ?

I was able to run code till : #print files  
for file in files:  
print(file.filename)
